Insert error???
-
I am trying to insert a row into a access database with information taken from user input. Here is the code i am using. It will not build i get an Constant expression is required error. can someone please tell me how to insert a row into a database with the users input. Thank you, Santana Try Const insertstr As String = "insert into newAuthors (authorID,firstName,lastName) values (" & txtacctnum.Text & "," & txtstartdate.Text & "," & txtenddate.Text & ")" Dim cnn As New OleDbConnection(strCnn) Dim cmd As New OleDbCommand(insertstr, cnn) cnn.Open() cmd.ExecuteNonQuery() cnn.Close() Catch oleDbExceptionParameter As System.Data.OleDb.OleDbException MsgBox("Invalid Query") End Try
-
I am trying to insert a row into a access database with information taken from user input. Here is the code i am using. It will not build i get an Constant expression is required error. can someone please tell me how to insert a row into a database with the users input. Thank you, Santana Try Const insertstr As String = "insert into newAuthors (authorID,firstName,lastName) values (" & txtacctnum.Text & "," & txtstartdate.Text & "," & txtenddate.Text & ")" Dim cnn As New OleDbConnection(strCnn) Dim cmd As New OleDbCommand(insertstr, cnn) cnn.Open() cmd.ExecuteNonQuery() cnn.Close() Catch oleDbExceptionParameter As System.Data.OleDb.OleDbException MsgBox("Invalid Query") End Try
-
I am trying to insert a row into a access database with information taken from user input. Here is the code i am using. It will not build i get an Constant expression is required error. can someone please tell me how to insert a row into a database with the users input. Thank you, Santana Try Const insertstr As String = "insert into newAuthors (authorID,firstName,lastName) values (" & txtacctnum.Text & "," & txtstartdate.Text & "," & txtenddate.Text & ")" Dim cnn As New OleDbConnection(strCnn) Dim cmd As New OleDbCommand(insertstr, cnn) cnn.Open() cmd.ExecuteNonQuery() cnn.Close() Catch oleDbExceptionParameter As System.Data.OleDb.OleDbException MsgBox("Invalid Query") End Try
================================================================= I think that , if the authorid is integer you must use ....cint(txtacctnum.Text ).... because (textbox?.text) will return string and authorid is integer !!!! wrong Think Before Begin