Hi Folks, I need quick help. I was access 2003 (OLeDB) as a database and all was fine. Now I have decided to use sql 2005 and that is where the problem is. I am listing the code below;
General declaration I have this;
At form load I have this code
To add the record the code is as shown
As I said it used to work fine ith access but it doesn't work with sql server 2005. It gives the error message;
General declaration I have this;
VB.NET:
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
At form load I have this code
VB.NET:
con.ConnectionString = "Data Source=HEADIT\SQLLOCAL;Initial Catalog=Address;Persist Security Info=True;User ID=sa;Password=logs1lumber"
con.Open()
Sql = "SELECT * FROM tblContacts"
da = New SqlDataAdapter(sql, con)
da.Fill(ds, "AddressBookDA")
con.Close()
To add the record the code is as shown
VB.NET:
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("AddressBookDA").NewRow()
dsNewRow.Item("FirstName") = txtFirstName.Text
dsNewRow.Item("Surname") = txtSurname.Text
dsNewRow.Item("Address1") = txtAddress1.Text
ds.Tables("AddressBookDA").Rows.Add(dsNewRow)
da.Update(ds, "AddressBookDA")
MsgBox("New Record added to the Database")
As I said it used to work fine ith access but it doesn't work with sql server 2005. It gives the error message;
da.update is highlighted.Update requires a valid InsertCommand when passed DataRow collection with new rows.