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.
 
As I stated before, 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")
instead of the dataAdapter (daStatus2.tables(0).TableName). DataAdapters don't have Tables and that's why the error message "Tables is not a member of System.Data.SQLClient.SQLDataAdapter" is received.
Also, when performing the search a second time, you would receive an error that multiple bindings aren't permitted since the textBox already has a dataBinding. Of course you could remove the dataBinding (clear) and then add it back, but then there is no sense in using dataBindings at all. It would be best to simply use a dataReader and set the text property of the textBox. Here's a link to a sample app using this idea: DBSearchQuery.zip

Since multiple searches are to be done, I would suggest reading the entire Table into a dataSet or dataTable and doing a search in that dataSource.

As xero said, the switch from ADO to ADO.NET is "still just a learning process i need to get through". ADO.NET is more powerful (in my opinion anyway) and therefore simpler things may seem more complex.
 
Well this is a little further down the line and i have figured out how to read in information to a textbox, with both databindings and Datareaders, but now the problem i am having is understand Databindings fully...

What i think databindings does it binds the data to a textbox lets say and if you change the textbox shouldn't that in theory change the data set that its bound to???

If not how can i go about doing this. I have a bunch of textboxes with Databindings to a Dataset thats being read in from a table. What I would like to do is be able to change the textbox and then update the table from there. How is this possible?

THANKS!
 
If you are using dataBindings, it should update once the text changes in the textbox.
It depends on how you have it set up as to when the changes are made in the DataTable. Usually when the position of the BindingManagerBase is changed the changes are made in the dataTable. You may have to call BindingManagerBase.EndCurrentEdit.

As always with using dataBindings, I suggest using the DataForm Wizard provided by Visual Studio as a starting point to learning how to use dataBindings. You answer question provided by the Wizard (which connection to use; which tables and fields you want included; dataGrid or seperate controls; navigation controls; update, cancel buttons; ...) then the wizards creates the typed dataset and all the code. You can the check out the code to see how it's done and modify code to suit your needs.
 
hi..
try this... it works if you dont want to bind...

dim myxs() as datarow
txtfname.Text = (MyXs(0).Item("userfname").ToString)
txtlname.Text = (MyXs(0).Item("userlname").ToString)
txtdate.Text = (MyXs(0).Item("userdate").ToString)
 
I never followed up on this, but i just wanted to let you guys knowwhat i did. I have now become considerably more knowledgable withADO.net. What i did was just use the datareader for the textboxes thati wanted to populate the information into the fields. And as far as theinformation that has multiple lines I just used the data adapter tofill a datagrid and create datatables wherever necessary.... You guyshelped me considerably and i appreciate it.

Thanks!
 
Back
Top