Contestoas
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.SqlC onnection( myConnecti on)
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()
Dim sqlConn As New System.Data.SqlClient.SqlC
Dim da As New SqlClient.SqlDataAdapter("
Dim ds As New DataSet
sqlConn.Open()
da.AcceptChangesDuringFill
da.Fill(ds, "Test")
Dim r As DataRow = ds.Tables("Test").NewRow()
r("Test1") = "text1"
r("Test2") = "text2"
ds.Tables("Test").Rows.Add
da.Update(ds, "Test")
sqlConn.Close()
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.