asp.net INSERT INTO 语句的语法错误.使用的是access
INSERTINTO语句的语法错误。说明:执行当前Web请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息:...
INSERT INTO 语句的语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
源错误:
行 48: Dim cmd As New OleDbCommand(strsql, conn)
行 49: conn.Open()
行 50: cmd.ExecuteNonQuery()
行 51: conn.Close()
行 52: message.Text = "已成功留言"
源文件: C:\Inetpub\wwwroot\rr02\WebForm1.aspx.vb 行: 50
堆栈跟踪:
[OleDbException (0x80040e14): INSERT INTO 语句的语法错误。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66
rr02.WebForm1.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\rr02\WebForm1.aspx.vb:50
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
下面是编写的程序
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=" & Server.MapPath("../rr02/ly.mdb"))
Dim strsql As String
strsql = "insert into ly1(title,body,name,time) values('" + title.Text + "','" + body.Text + "','" + name.Text + "'," + Now() + ")"
Dim cmd As New OleDbCommand(strsql, conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
message.Text = "已成功留言"
Dim adp As New OleDbDataAdapter("select * from ly1 order by time desc", conn)
Dim ds As New DataSet
adp.Fill(ds, "user")
DataGrid1.DataSource = ds.Tables("user").DefaultView
DataGrid1.DataBind()
End Sub 展开
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
源错误:
行 48: Dim cmd As New OleDbCommand(strsql, conn)
行 49: conn.Open()
行 50: cmd.ExecuteNonQuery()
行 51: conn.Close()
行 52: message.Text = "已成功留言"
源文件: C:\Inetpub\wwwroot\rr02\WebForm1.aspx.vb 行: 50
堆栈跟踪:
[OleDbException (0x80040e14): INSERT INTO 语句的语法错误。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66
rr02.WebForm1.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\rr02\WebForm1.aspx.vb:50
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
下面是编写的程序
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=" & Server.MapPath("../rr02/ly.mdb"))
Dim strsql As String
strsql = "insert into ly1(title,body,name,time) values('" + title.Text + "','" + body.Text + "','" + name.Text + "'," + Now() + ")"
Dim cmd As New OleDbCommand(strsql, conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
message.Text = "已成功留言"
Dim adp As New OleDbDataAdapter("select * from ly1 order by time desc", conn)
Dim ds As New DataSet
adp.Fill(ds, "user")
DataGrid1.DataSource = ds.Tables("user").DefaultView
DataGrid1.DataBind()
End Sub 展开
1个回答
展开全部
strsql = "insert into ly1(title,body,name,time) values('" + title.Text + "','" + body.Text + "','" + name.Text + "'," + Now() + ")"
改成
strsql = "insert into ly1(title,body,name,time) values('" + title.Text + "','" + body.Text + "'悉脊扮,'" + name.Text + "','睁灶" + Now() + "')"
记得..日期型也野御要加'' 单引号..除了整型或者之类的不用
改成
strsql = "insert into ly1(title,body,name,time) values('" + title.Text + "','" + body.Text + "'悉脊扮,'" + name.Text + "','睁灶" + Now() + "')"
记得..日期型也野御要加'' 单引号..除了整型或者之类的不用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询