Dear All,
I have wriiten the following code to add a new row in author table. But it is generating an error("Update requires a valid InsertCommand when passed DataRow collection with new rows.")
Please help me on this.
Dim con As New SqlConnection(" Data Source=.;Initia l Catalog=student ;Integrated Security=True")
Dim cmd As New SqlCommand("Sel ect * from author", con)
con.Open()
Dim adp As New SqlDataAdapter( cmd)
Dim ds As New DataSet()
Dim dt As DataTable
Dim dr As DataRow
adp.Fill(ds, "author")
dt = ds.Tables("auth or")
dr = dt.NewRow()
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox3.Text
dt.Rows.Add(dr)
adp.Update(ds, "author")
con.Close()
Regards
Harman
I have wriiten the following code to add a new row in author table. But it is generating an error("Update requires a valid InsertCommand when passed DataRow collection with new rows.")
Please help me on this.
Dim con As New SqlConnection(" Data Source=.;Initia l Catalog=student ;Integrated Security=True")
Dim cmd As New SqlCommand("Sel ect * from author", con)
con.Open()
Dim adp As New SqlDataAdapter( cmd)
Dim ds As New DataSet()
Dim dt As DataTable
Dim dr As DataRow
adp.Fill(ds, "author")
dt = ds.Tables("auth or")
dr = dt.NewRow()
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox3.Text
dt.Rows.Add(dr)
adp.Update(ds, "author")
con.Close()
Regards
Harman
Comment