DB field update

kcwallace

Well-known member
Joined
May 27, 2004
Messages
172
Location
Irvine, CA
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:

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.
 
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.
 
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?
 
Just use the ParameterCollection of the Command, then the length
of your data doesnt matter, and prevents you from getting sqlinjections.

And there are alot of examples in the help or that.
 
Back
Top