Databinding Question

gearbolt

Member
Joined
Mar 16, 2003
Messages
14
I have two text boxes that are bound to a dataset, there is also a Sqlconnection, SqlDataadapter in use. VB.Net generated the Insert, Update and Delete statements for the dataset but I cant figure out how to get the new data out of the textboxes and into the database. This is the code that was generated by Visual Studio. Thanks for the help.

SqlInsertCommand1

Me.SqlInsertCommand1.CommandText = "INSERT INTO dbo.Users(UserName, UserPassword) VALUES (@UserName, @UserPassword); " & _
"SELECT UserName, UserPassword FROM dbo.Users WHERE (UserName = @UserName)"
Me.SqlInsertCommand1.Connection = Me.SqlConnection1
Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UserName", System.Data.SqlDbType.VarChar, 20, "UserName"))
Me.SqlInsertCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UserPassword", System.Data.SqlDbType.VarChar, 20, "UserPassword"))
 
Do you want to databind the textboxes to the dataset?
Or, do you simply want to input the textbox.text into a field in your dataset?

The data adapter will take care of implementing the insert command. You simply call an update once you
have manipulated your dataset.
 
Since your textboxes are already bound, theres nothing else to do, simply call the Update method of the DataAdapter.
 
I have already databinded the textboxes to the dataset. When I hit the the command button to fill the textboxes I get the first record from the database. But know I want to enter some new information into the textbox and update the database. I am new to VB.Net and would not normally use databinding but I am trying to learn everything VB.Net offers.
 
Yes I know, thats why I said...
Since your textboxes are already bound, theres nothing else to do, simply call the Update method of the DataAdapter.
 
the rowstate is changed only when u move off the current row. so if u change
the value in the textbox, move to the next row, and then examine the
rowstate property, u will find that it has indeed changed to "Modified"

To cause the rowstate to change without moving off the row, call the
EndCurrentEdit method on the underlying bindingcontext object that u create,
or if uve not specifically created a bindingcontext, use the following
syntax (possibly in the click event of the OK/Save button)

Me.BindingContext(dataset, "tablename").EndCurrentEdit
 
Back
Top