Access:
Above works well and inserts a record. Primary key is getting violated properly if I try to insert the same record again.
But below doesnt insert any record. Code is executed properly and a message box is also shown. If I dont stop the project from running state and insert the same record again I get primary key violation notice but if I stop the program and re-execute it inserts the record again.
I am using SQL server express - It seems it has some thing to do with the same.
SQL Server:
VB.NET:
Dim cn As New OleDbConnection
cn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0; data source=c:\db1.mdb;"
cn.Open()
Dim cmd As New OleDbCommand("insert into tblEmp values (2,'Mike','Accountant',#10/10/1988#)", cn)
Dim i = cmd.ExecuteNonQuery
MsgBox("Record Inserted")
Above works well and inserts a record. Primary key is getting violated properly if I try to insert the same record again.
But below doesnt insert any record. Code is executed properly and a message box is also shown. If I dont stop the project from running state and insert the same record again I get primary key violation notice but if I stop the program and re-execute it inserts the record again.
I am using SQL server express - It seems it has some thing to do with the same.
SQL Server:
VB.NET:
Dim cn1 As New SqlConnection
cn1.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"
cn1.Open()
Dim cmd1 As New SqlCommand("insert into tblEmp values (4,'Mike','Accountant','10/10/1988')", cn1)
Dim j = cmd1.ExecuteNonQuery
MsgBox("Record Inserted")
Last edited: