jeff lee khong wai
New member
I create a new database by Visual Studio. Add table and want to use VB.NET to add data to the table.
Here is my code:
Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MAAMedicareDB.mdf;Integrated Security=True;User Instance=True")
Dim cmd As New System.Data.SqlClient.SqlCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "INSERT Centers (centerName, centerADD) VALUES ('USA center', 'Your house')"
cmd.Connection = sqlConnection1
sqlConnection1.Open()
cmd.ExecuteNonQuery()
sqlConnection1.Close()
MsgBox("Run", MsgBoxStyle.Information, "run")
My program just run the code without error. But when i open my database, nothing change. That's mean even the code run but no data add in my database.
I sure the connection is ok because i able to retrieve data.
Is it anything i need to set? or I am not permit to write to the database?
Any setting need to do?
Please help me. Urgent...
Thank you
Here is my code:
Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MAAMedicareDB.mdf;Integrated Security=True;User Instance=True")
Dim cmd As New System.Data.SqlClient.SqlCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "INSERT Centers (centerName, centerADD) VALUES ('USA center', 'Your house')"
cmd.Connection = sqlConnection1
sqlConnection1.Open()
cmd.ExecuteNonQuery()
sqlConnection1.Close()
MsgBox("Run", MsgBoxStyle.Information, "run")
My program just run the code without error. But when i open my database, nothing change. That's mean even the code run but no data add in my database.
I sure the connection is ok because i able to retrieve data.
Is it anything i need to set? or I am not permit to write to the database?
Any setting need to do?
Please help me. Urgent...
Thank you