-
help !!!!!!!!!!!!!!!!!!!
hi all ~~
i have one stupid Question want to ask
i have using a insert command to add the data into the Access database but i got an error
--------------------------------------------------------------
coding
--------------------------------------------------------------
Imports System.Data
Imports System.Data.OleDb
#End Region
Dim mypath = Application.StartupPath & "\RestaurantBookingDb.mdb"
Dim mypassword = ""
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=" & mypassword)
Dim cmd As OleDbCommand
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Dim strSQL As String
'Addnew
strSQL = "Insert Into CustomersBooking (cname,chp) Values (" & "'" & cname.Text & "'" & "," & "'" & chp.Text & "')"
conn.Open()
'Command Object to Execute the SQL
Dim ocmd As OleDbCommand = New OleDbCommand(strSQL, conn)
ocmd.ExecuteNonQuery()
'Cleanup
ocmd.Dispose()
conn.Close()
End Sub
End Class
---------------------------------------------
End
---------------------------------------------
is there got any error on it ???
it pointed to here --> ocmd.ExecuteNonQuery()
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
-
this line:
strSQL = "Insert Into CustomersBooking (cname,chp) Values (" & "'" & cname.Text & "'" & "," & "'" & chp.Text & "')"
should look like this :
strSQL = "Insert Into CustomersBooking (cname,chp) Values (""" & cname.Text & """,""" & chp.Text & """)"
dont use: '
use: "
a little suggestion, if i may: think of better thread names when opening new thread, you are lucky people read your thread when it only says help. everyone seeks help on forums. well, almost everyone.
have a nice day.
-