kcwallace Posted March 5, 2006 Posted March 5, 2006 I need to update a field in code using a method similar to the old adodb method of recordset.addnew recordset("field1")="eee" recordset("field2")="rrrr" recordset.update I am having trouble getting adonet to do something similar. I did research and was pointed to something like the following: Dim SQL As String = "SELECT * FROM table1" Dim cmd As New SqlCommand(SQL, ADOCnn) Dim DA = New SqlDataAdapter(cmd) Dim DS As New DataSet DA.SelectCommand = cmd DA.Fill(DS) Dim table As DataTable = DS.Tables(0) ' Use the NewRow method to create a DataRow 'with the table's schema. Dim newRow As DataRow = table.NewRow() ' Set values in the columns: newRow("test") = "NewCompanyID" 'newRow("CompanyName") = "NewCompanyName" ' Add the row to the rows collection. table.Rows.Add(newRow) MsgBox(DS.Tables(0).Columns(0).ColumnName) The message box at the end reports back the correct data, but nothing is added to the database. Am I using the correct method, or is another method available. I cannot use a "INSERT" statement because the string becomes too long. Quote Go Beavs!!!
Administrators PlausiblyDamp Posted March 5, 2006 Administrators Posted March 5, 2006 You will also need to define an appropriate InsertCommand, UpdateCommand and DeleteCommand for the DataAdapter, then use the DA.Update(...) method to push the changes back to the DB. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
kcwallace Posted March 6, 2006 Author Posted March 6, 2006 define an appropriate InsertCommand, UpdateCommand and DeleteCommand for the DataAdapter, then use the DA.Update(...) method to push the changes back to the DB. Can you provide me a link to a help file to accomplish your suggestion? Quote Go Beavs!!!
FZelle Posted March 11, 2006 Posted March 11, 2006 Just use the ParameterCollection of the Command, then the length of your data doesn't matter, and prevents you from getting sqlinjections. And there are alot of examples in the help or that. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.