kcwallace
Well-known member
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:
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.
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:
Code:
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 tables 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.