Hi Guys,
I've been working the this problem for two days now and I am starting to get really frustrated!! All I need to do is to be able to add a new row into a database table with some new data in it! But even the following example code does not work for me...
This example is from the Microsoft Knowledgebase with some lines added in to insert a row and add 'New_Contact' in the ContactName field.Code:Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click MsgBox("Attempting to update a DataTable that is Nothing...") Dim cn As New SqlConnection("Server=vcomp;" & _ "integrated security=true;database=northwind") Dim da As New SqlDataAdapter("Select * From Customers", cn) Dim cb As New SqlCommandBuilder(da) Dim ds As New DataSet Dim dr As DataRow da.Fill(ds, "Customers") dr = ds.Tables("Customers").NewRow ds.Tables(0).Rows(0)!ContactName = "New_Contact" ds.Tables(0).Rows.Add(dr) da.Update(ds, "Customers") cn.Close() cn = Nothing End Sub
I get the following error on the da.Update(ds, "Customers") line...
What is wrong?? What am I missing?? Please help meAn unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.![]()





Reply With Quote