Link to home
Create AccountLog in
Avatar of Contestoas
ContestoasFlag for Norway

asked on

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

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

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

        ds.Tables("Test").Rows.Add(r)

        da.Update(ds, "Test")

        sqlConn.Close()
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer