Hello,
I'm new in vb.net. I have a problem in inserting a new row to a MS Access database table.
There is no error message comes out when i run my program, but when i check my MS Access table, there is no record inserted. So, i don't know which line is incorrect.
Here is my code:
Thanks...
I'm new in vb.net. I have a problem in inserting a new row to a MS Access database table.
There is no error message comes out when i run my program, but when i check my MS Access table, there is no record inserted. So, i don't know which line is incorrect.
Here is my code:
Dim desc, itemID As String
itemID = txtItemID.Text
desc = txtItemDesc.Tex t
Dim myOleDbConnecti on As OleDb.OleDbConn ection
Dim insertCommand As String
Dim myConnectionStr ing As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=E:\Lectu re\CS220\Progra m backup 3\Ai Ling Ka Salon System\database \login.mdb;User ID=Admin;Passwo rd=;"
insertCommand = "INSERT INTO tblLogin (username, password) VALUES(desc, itemID);"
myOleDbConnecti on = New OleDb.OleDbConn ection(myConnec tionString)
Dim myOleDbCommand As New OleDb.OleDbComm and(insertComma nd, myOleDbConnecti on)
myOleDbCommand = myOleDbConnecti on.CreateComman d
myOleDbCommand. CommandType = CommandType.Tex t
myOleDbCommand. CommandText = insertCommand
myOleDbConnecti on.Open()
Dim temp_num As Integer
Try
temp_num = myOleDbCommand. ExecuteNonQuery
Catch ex As Exception
Trace.WriteLine (ex.ToString)
End Try
myOleDbConnecti on.Close()
itemID = txtItemID.Text
desc = txtItemDesc.Tex t
Dim myOleDbConnecti on As OleDb.OleDbConn ection
Dim insertCommand As String
Dim myConnectionStr ing As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=E:\Lectu re\CS220\Progra m backup 3\Ai Ling Ka Salon System\database \login.mdb;User ID=Admin;Passwo rd=;"
insertCommand = "INSERT INTO tblLogin (username, password) VALUES(desc, itemID);"
myOleDbConnecti on = New OleDb.OleDbConn ection(myConnec tionString)
Dim myOleDbCommand As New OleDb.OleDbComm and(insertComma nd, myOleDbConnecti on)
myOleDbCommand = myOleDbConnecti on.CreateComman d
myOleDbCommand. CommandType = CommandType.Tex t
myOleDbCommand. CommandText = insertCommand
myOleDbConnecti on.Open()
Dim temp_num As Integer
Try
temp_num = myOleDbCommand. ExecuteNonQuery
Catch ex As Exception
Trace.WriteLine (ex.ToString)
End Try
myOleDbConnecti on.Close()
Thanks...
Comment