Dataset and Textboxes

xero

Member
Joined
Nov 8, 2004
Messages
12
Programming Experience
1-3
Hi i am a newbie when it comes down to .net programming. Especially VB.net. I am fluent in VBScript and ASP but not VB and VB.net so please bare with me. My current problem is I would like to do the simple thing known as assigning a textbox the value thats in the database. In vbscript it would be something like this...

tbx1.text = rsName("FieldName")

But in VB.net i have no idea... Can someone please help.. This is absolutely driving me insane.
 
textbox1.text = bindingmanager("text","Table","Database") is roughly what you want, i dont know the exact command & arguements but it's close to that, i can post more on that tonight.
 
I do not believe that syntax is doable.....

Also i am curious about one thing... If i where to link the textboxes to the dataset in the formload.... Then that would automatically make the textboxes whatever the dataset consisted of?

And if that is true how would i jump to a specific record?

For example if i wanted to look up record a record carying the number 123 how would i do this???? THanks again everyone!
 
The correct syntax to bind a control to a field in a dataset is:

ControlName.DataBindings.Add(New System.Windows.Forms.Binding(propertyName, dataSource, dataMember))

To look up a record, you could filter a dataView or use a SQL statement to retrieve only the record you want. As always with .NET there are many solutions.

I would suggest reading a little about ADO.NET. The MSDN site is always a good place to start (Here's a link) and there are many other tutorials on the net.
 
i was close enough for only haveing my limited memory on hand:

Textbox1.DataBindings.Add("text", DataSource, "Field")
 
Thats dandy, but im still having problems...

Im starting to get pissed off too because this would only take two lines of freaking code to get this done in plain ADO.. but with ADO.net it's a freaking headache... Anyways i know it's still just a learning process i need to get through... Heres what i am doing....

Private Sub Btn_Lookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_lookup.Click
Dim daStatus2 As New SqlDataAdapter("Select * from tbl_Status where Workorder=" & tbx_WorkOrder.Text & " order by StatusDate ASC", conSQLStatusCheck)
Dim dsStatusCheck As DataSet = New DataSet("tbl_status")
daStatus2.Fill(dsStatusCheck)
tbx_COM.DataBindings.Add("TEXT", daStatus2, "status")
tbx_Company.DataBindings.Add("TEXT", daStatus2, "Company")
tbx_CompanyRep.DataBindings.Add("TEXT", daStatus2, "CompanyRep")
tbx_Finish.DataBindings.Add("TEXT", daStatus2, "Finish")
End Sub


When i click on a button it's suppose to basically look up the info based on what the number is in the textbox yet i keep getting this error:

An unhandled exception of type 'System.ArgumentException' ocurred in systemWindows.Forms.dll

Additional Infomration: Can't Bind to property or column status on DataSource.
 
The second parameter in this line:
tbx_COM.DataBindings.Add("TEXT", daStatus2, "status")
should be the DataSource. It should read:
tbx_COM.DataBindings.Add("TEXT", dsStatusCheck.Tables(0), "status")

This won't really work for multiple searches. The second time you click the button, you'll get a message stating that there would be multiple dataBindings when you try to add the binding again (if you make sure to open the connection before trying to fill the dataAdapter, close it after you're done too).

If you are looking to do multiple searches, the best thing would be to look at using a dataView and typed dataSets.
 
Then how exactly would i write it so I could post do a search multiple times?... That's what i was originally intending. Is there anyway you can write me up a small example. Thanks!
 
Data Binding

try the following :

Private Sub Btn_Lookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_lookup.Click
Dim daStatus2 As New SqlDataAdapter("Select * from tbl_Status where Workorder=" & tbx_WorkOrder.Text & " order by StatusDate ASC", conSQLStatusCheck)
Dim dsStatusCheck As DataSet = New DataSet("tbl_status")
daStatus2.Fill(dsStatusCheck)
tbx_COM.DataBindings.Add("TEXT", daStatus2, daStatus2.tables(0).TableName & "status")
tbx_Company.DataBindings.Add("TEXT", daStatus2,daStatus2.tables(0).TableName & "Company")
tbx_CompanyRep.DataBindings.Add("TEXT", daStatus2,daStatus2.tables(0).TableName & "CompanyRep")
tbx_Finish.DataBindings.Add("TEXT", daStatus2, "Finish")
End Sub
 
Hi xero

sorry this is what I meant . . .

Private Sub Btn_Lookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_lookup.Click
Dim daStatus2 As New SqlDataAdapter("Select * from tbl_Status where Workorder=" & tbx_WorkOrder.Text & " order by StatusDate ASC", conSQLStatusCheck)
Dim dsStatusCheck As DataSet = New DataSet("tbl_status")
daStatus2.Fill(dsStatusCheck)
tbx_COM.DataBindings.Add("TEXT", daStatus2, daStatus2.tables(0).TableName & ".status")
tbx_Company.DataBindings.Add("TEXT", daStatus2,daStatus2.tables(0).TableName & ".Company")
tbx_CompanyRep.DataBindings.Add("TEXT", daStatus2,daStatus2.tables(0).TableName & ".CompanyRep")
tbx_Finish.DataBindings.Add("TEXT", daStatus2,daStatus2.tables(0).TableName & ".Finish")
End Sub

see if that works for u
 
Back
Top