Sunday, December 11, 2011

How do I manually add data from textbox to datatable using VB 2005 with MySQL?

WARNING! THIS CODE DOESN'T WORK!



currencymanager.addnew()

datatable.defaultview(currencymanager.鈥?= textbox.text



command = new mysqlcommandbuilder(dataadapter)

dataadapter.updatecommand = command.getupdatecommand

dataadapter.update(datatable)

currencymanager.endcurrentedit()



if currencymanager.count = 2, position can be 0 or 1. after calling addnew(), count = 3 position = 2. when i try to assign the value of textbox.text to its datatable column using the code above, error because datatable has no position 2.



my update code also doesn't work. but if i copy paste it after the first update code, making it redundant, my database gets updated successfully.



thanks for anyone who may correct the code.How do I manually add data from textbox to datatable using VB 2005 with MySQL?
The following code uses the dsEmployees DataSet. It locates the DataTable named Manager in the Tables collection. It then selects the first DataRow object, and changes the value of its LastName item to ';Stephens'; (the update data).



dsEmployees.Tables(';Managers';) _

.Rows(0).Item(';LastName';) = ';Stephens';



' The above statement is actually one line.

' Answers does not display it properly.

' So, I used an underscore character to break it into two lines.

' You can combine the two lines, and omit the underscore.

' In the expression to the left of the equal sign, there are no spaces.



If you want to update by using the contents of a TextBox, then simply use, i.e., TextBox1.Text for the update data.



__________-

No comments:

Post a Comment