databinding

johnnyc

New member
Joined
Mar 3, 2004
Messages
2
Ok i have a table called hole. The table Hole has a holeid

Hole
HoleId
1
2
3

I am tring to databind the inform into a label and i want to retrieve the information from HoleId for hole 2 any suggestions
The code that i tried is the following where am i going wrong

lblHole2.Databinding.Add("Text",ds.Tables["Hole"].Columns["1"],"HoleId");
 
There is a method called BindingContext that does quite what you want.

If in the form you use the table hole you assign a DataRow like this:
[VB]
Dim dr As DataRow = Me.BindingContext(hole).Current
[/VB]
This line will assign the current working row of the table hole to the DataRow dr.

Having this, just use this line to retrieve the value on the HoleID column:
[VB]
Dim HoleID As Integer = dr("HoleIDColumnName")
[/VB]

Alex :p
 
The code for SD is the same as what Alex provided...


C#:
DataRow dr = Me.BindingContext(hole).Current;

Int HoleID = dr("HoleIDColumnName");
 
Back
Top