Really confused...trying to access data in a bound datasource

peterc

Member
Joined
Jan 5, 2016
Messages
16
Programming Experience
1-3
The code below is part of a tab page form, they is used on event tabpage_enter

VB.NET:
Me.taChassis.Fill(Me.DsTTDJobs.chassis)

        bsChassis.Filter = "Chassis_Job_number = " & intchassisjobno & ""

        If txtchassiscerttype.Text = "LT400" Then rbChassisLT400.Checked = True Else rbChassisLT400.Checked = False
        If txtchassiscerttype.Text = "SODC" Then rbChassisSODC.Checked = True Else rbChassisSODC.Checked = False

        If txtchassisltr.Text = "LTR31002" Then rbChassisLTR31002.Checked = True Else rbChassisLTR31002.Checked = False
        If txtchassisltr.Text = "LTR34001" Then rbChassisLTR34001.Checked = True Else rbChassisLTR34001.Checked = False

        cbchassisTypeWork.SelectedText = txtchassistypework.Text

The problem I have is that even though there is data in the .text fields on the form, the checking does not see it, as I have debugged and hovered over the statements and the .text fields show ""

Why would this be?

One of the things I have been trying to establish is how to read data directly from the datasource? Can someone explain this to me?
 
Firstly, why would you fill the DataTable every time a control in the TabPage gets focus? If the DataTable is already populated then why populate it again?

As for the issue, I would suggest that you actually do what the thread title says but the code doesn't do, i.e. get the data from the data source. Instead of using the TextBoxes, use the Current property of the BindingSource to get the current item.
 
That is the newbie problem I am having. I cannot figure out the syntax for getting the information from the bindingsource.

Have spent more than enough hours on trying to figure it out...even the www has been no help, as just about every post talks about putting the data into the database....that part I already have sorted....it is getting the data from the database that I am having trouble sorting the syntax out for.
 
As I said, you use the Current property of the BindingSource. It exposes the current item from the data source. If the data source is a DataTable then the data actually comes from the DataView exposed by its DefaultView property, so the item itself will be a DataRowView. You can get field data into and out of a DataRowView by column name or index, just like a DataRow. As you're using a typed DataSet, you can get an appropriately-typed DataRow from the Row property of the DataRowView. E.g.
'The Current property is type Object because you can bind a list of any type of objects.
Dim currentItem As Object = myBindingSource.Current

'If the data source is a DataTable then the items are all DataRowViews.
Dim view = DirectCast(currentItem, DataRowView)

'Every DataRowView is a view of a DataRow.
Dim untypedRow As DataRow = view.Row

'If you've bound a typed DataTable then the row is a typed DataRow.
Dim typedRow = DirectCast(untypedRow, MyTypedDataRowType)
Now you can get data in and out using properties with full Intellisense.
 
Back
Top