主题:大虾们,救命啊!
我用vb.net添加了两个文本框,一个按钮,一个标签,
想通过单击按钮后,把两个文本框的内容写入数据库中!
我webform1.aspx.vb的代码是:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Inetpub\wwwroot\WebApplication1\db1.mdb")
Dim strsql As String = "insert into user(id,passwd) values('" & TextBox1.Text & " ','" & TextBox2.Text & " ')"
Dim cmd As New OleDbCommand(strsql, conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Label1.Text = "已经加入,请认真核对!"
End Sub
我觉得没有错,可是当我按下按钮后却告诉我下面这些,我究竟哪里错了?帮我解决一下啊,万分感谢!急啊!
“/WebApplication1”应用程序中的服务器错误。
--------------------------------------------------------------------------------
INSERT INTO 语句的语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
源错误:
行 33: Dim cmd As New OleDbCommand(strsql, conn)
行 34: conn.Open()
行 35: cmd.ExecuteNonQuery()
行 36: conn.Close()
行 37: Label1.Text = "已经加入,请认真核对!"
源文件: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.vb 行: 35
堆栈跟踪:
[OleDbException (0x80040e14): INSERT INTO 语句的语法错误。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
WebApplication1.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
想通过单击按钮后,把两个文本框的内容写入数据库中!
我webform1.aspx.vb的代码是:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Inetpub\wwwroot\WebApplication1\db1.mdb")
Dim strsql As String = "insert into user(id,passwd) values('" & TextBox1.Text & " ','" & TextBox2.Text & " ')"
Dim cmd As New OleDbCommand(strsql, conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Label1.Text = "已经加入,请认真核对!"
End Sub
我觉得没有错,可是当我按下按钮后却告诉我下面这些,我究竟哪里错了?帮我解决一下啊,万分感谢!急啊!
“/WebApplication1”应用程序中的服务器错误。
--------------------------------------------------------------------------------
INSERT INTO 语句的语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
源错误:
行 33: Dim cmd As New OleDbCommand(strsql, conn)
行 34: conn.Open()
行 35: cmd.ExecuteNonQuery()
行 36: conn.Close()
行 37: Label1.Text = "已经加入,请认真核对!"
源文件: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.vb 行: 35
堆栈跟踪:
[OleDbException (0x80040e14): INSERT INTO 语句的语法错误。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
WebApplication1.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573