marshabanana
New Member
hi all, <BR>i have been trying to connect to MS Access database and insert a record into it , but i get a syntax error.The table name is emp in the test1.mdb database.The fields in the emp table are empno,occupation, email-id ,phonenumber.<BR>this is the code:<BR>----------------<BR>Private Sub create_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles create.Click<BR><BR> Dim sqlcmd<BR> sqlcmd = "INSERT INTO emp (empno, occupation, email-id, phonenumber)values(" & Request.Form("text_empno") & ",'" & Request.Form("text_occp") & "','" & Request.Form("text_email") & "'," & Request.Form("text_phone") & ")"<BR><BR> Dim myconn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=d:gayatrijunk est1.mdb;")<BR> myconn.Open()<BR> If myconn.State = 1 Then<BR><BR> Response.Write("connected")<BR> ElseIf myconn.State = 0 Then<BR><BR> Response.Write("not connected")<BR> End If<BR> Dim oledbcmd As New OleDb.OleDbCommand(sqlcmd, myconn)<BR> Dim empno1 As New OleDb.OleDbParameter("@empno", OleDb.OleDbType.Integer, 20)<BR> empno1.Value = http://aspmessageboard.com/archive/index.php/Request.Form("text_empno")<BR> oledbcmd.Parameters.Add(empno1)<BR> Dim occp1 As New OleDb.OleDbParameter("@occupation", OleDb.OleDbType.LongVarChar, 20)<BR> occp1.Value = Request.Form("text_occp")<BR> oledbcmd.Parameters.Add(occp1)<BR> Dim email1 As New OleDb.OleDbParameter("@email-id", OleDb.OleDbType.LongVarChar, 20)<BR> email1.Value = Request.Form("text_email")<BR> oledbcmd.Parameters.Add(email1)<BR> Dim phone1 As New OleDb.OleDbParameter("@phonenumber", OleDb.OleDbType.Integer, 20)<BR> phone1.Value = Request.Form("text_phone")<BR> oledbcmd.Parameters.Add(phone1)<BR> Dim i As Integer<BR> i = oledbcmd.ExecuteNonQuery()<BR> Response.Write(CStr(i))<BR> myconn.Close()<BR> <BR><BR><BR><BR> End Sub<BR>this the is the stacktrace:<BR>------------------------------<BR>[OleDbException (0x80040e14): Syntax error in INSERT INTO statement.]<BR> System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr)<BR> System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult)<BR> System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)<BR> System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult)<BR> System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method)<BR> System.Data.OleDb.OleDbCommand.ExecuteNonQuery()<BR> loginfortest.WebForm1.create_Click(Object sender, EventArgs e) in C:WINNTProfilesAdministratorVSWebCachesatyaloginfo rtestWebForm1.aspx.vb:65<BR> System.Web.UI.WebControls.Button.OnClick(EventArgs e)<BR> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)<BR> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)<BR> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)<BR> System.Web.UI.Page.ProcessRequestMain()<BR>---------------------------------------<BR>this is the error title<BR>---------------------<BR>Syntax error in INSERT INTO statement. <BR>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <BR><BR>Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.<BR><BR>Source Error: <BR><BR><BR>Line 63: oledbcmd.Parameters.Add(phone1)<BR>Line 64: Dim i As Integer<BR>Line 65: i = oledbcmd.ExecuteNonQuery()--->highlighted <BR>Line 66: Response.Write(CStr(i))<BR>Line 67: myconn.Close()<BR><BR>Please help me .<BR>Thankyou in advance,<BR>gayatri<BR> <BR>