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()
ContestoasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi Contestoas;

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

Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)

Fernando
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.