[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Using .net 2.0 to insert a single row of data

I need to add a row of data to a table. In my attempt below I receive an error message saying that I need a valid insertcommand. However, even if this would work, it looks a bit inefficient. Also, what I want to do is to add ONE row of data as efficient as possible and avoid the use of sql. (i.e. insert into test (test1,test2) values ("text1","text2")...)

        Dim sqlConn As New System.Data.SqlClient.SqlConnection(myConnection)
        Dim da As New SqlClient.SqlDataAdapter("Select * from Test", sqlConn)
        Dim ds As New DataSet

        da.AcceptChangesDuringFill = True
        da.Fill(ds, "Test")

        Dim r As DataRow = ds.Tables("Test").NewRow()
        r("Test1") = "text1"
        r("Test2") = "text2"


        da.Update(ds, "Test")

1 Solution
Fernando SotoRetiredCommented:
Hi Contestoas;

Try adding this line of code after you create the SqlDataAdapter.

Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)


Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now