In my application I'm passing a dataset ByRef with the constructor of FormWeergaveZoek. There are also four buttons to scroll through the values of the dataset (ButtonVolgend, Buttonvorig, ButtonBegin, ButtonEinde). The fields of the dataset are displayed in textboxes with databindings. All the values are displayed correctly, except Me.TextBoxCDID.DataBindings.Add("text", dsMyDataset, "tblCD.CDID") which is displaying the number of the row in the dataset and not the original number in the database. For exmple :
In my database a CD from The Stones has CDID 234, but in the dataset (datasetzoeken12) this record is in the first row (because this is the searchresult). So the displayed result in the textbox will be 1 and not the required 234.
Why is this????
The code of the form is the following:
Public Class FormWeergaveZoek
Inherits Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Dim dsMyDataset As DataSet
Public Sub New(ByRef Datasetzoeken12 As DataSet)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
dsMyDataset = Datasetzoeken12
End Sub
Private Sub FormWeergaveZoek_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBoxCDID.DataBindings.Add("text", dsMyDataset, "tblCD.CDID")
Me.TextBoxCDDetail.DataBindings.Add("text", dsMyDataset, "tblCD.CD")
Me.TextBox1.DataBindings.Add("text", dsMyDataset, "tblCD.programgroup")
Me.TextBoxCDdetailDescription.DataBindings.Add("text", dsMyDataset, "tblCD.DescriptionCD")
Me.TextBoxDatum.DataBindings.Add("text", dsMyDataset, "tblCD.date")
Me.CheckBoxActief.DataBindings.Add("text", dsMyDataset, "tblCD.active")
Me.LabelNumber.Text = (Me.BindingContext(dsMyDataset).Position + 1).ToString & " of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
End Sub
Private Sub ButtonVolgend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVolgend.Click
Me.BindingContext(dsMyDataset, "tblCD").Position = (Me.BindingContext(dsMyDataset, "tblCD").Position + 1)
Me.LabelNumber.Text = (Me.BindingContext(dsMyDataset, "tblCD").Position + 1).ToString & " of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
End Sub
Private Sub ButtonVorig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVorig.Click
Me.BindingContext(dsMyDataset, "tblCD").Position = Me.BindingContext(dsMyDataset, "tblCD").Position - 1
Me.LabelNumber.Text = (Me.BindingContext(dsMyDataset, "tblCD").Position - 1).ToString & " of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
End Sub
Private Sub ButtonEinde_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEinde.Click
Me.BindingContext(dsMyDataset, "tblCD").Position = Me.BindingContext(dsMyDataset, "tblCD").Count
Me.LabelNumber.Text = (Me.BindingContext(dsMyDataset, "tblCD").Count).ToString & " of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
End Sub
Private Sub Buttonbegin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonbegin.Click
Me.BindingContext(dsMyDataset, "tblCD").Position = 1
Me.LabelNumber.Text = "1 of " & Me.BindingContext(dsMyDataset, "tblCD").Count.ToString
End Sub
End Class
I checked your program. You have some confusing problems:
1- The dataset you are using 'DataSetZoeken12' already has a list of typed columns, one named "CDID" that is an autoincrement column, and then you are adding another tblCD.CDID untyped column to it. It binds to the Typed one that is actually "tblCD.CDID" and contaisn values of 0,1,2,3,... So thats why you are facing this problem.
2- Even if you generate dataset with the OleDbDataAdapterzoeken1 still you will face problem, because you are changing the select text of dataadapter and different set of columns are chosen and then still trying to fill the previous dataset with it. In this manner you are trying to bind to an Untyped Dataset, that causes problem when you are for example binding a Text property to an Integer. So you may build an adapter with the command text of strSQLzoeken and generate a dataset with it, and then change the select command based on the selection. Remember in this manner you are not changing the column collection of the dataadapter, just applying some filters.
Last edited by Lunatic3; Nov 18th, 2003 at 10:18 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Thanks for taking the time to check my 'crappy' code. I know it needs some refreshments, but I'm a newbie so...
BUt there are some things I don't understand:
- Why has datasetzoeken12 some typed columns? Is this because I created the dataset with the wizard and because it is based on OleDBDataAdapterZOeken1?
- Then you say I add some other columns to the datasetzoeken12, don't I use the same columns as when the dataset was created?
- How would you solve this problem, could you please give me a code example? I don't understand your suggestion stated in your point 2.
I hope you can help me, because I'm getting frustrated on this problem.