Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Go Beavs!!!
Posted
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?

Go Beavs!!!
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...