请问为什么程序编译没有错,但是执行时却有错??--->异常详细信息: System.Data.OleDb.OleDbException
<%@ Page Language="VB" Debug="true" %><%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Register TagPrefix="mynews" TagName="top" Src="ascx/top.ascx" %>
<%@ Register TagPrefix="mynews" TagName="footer" Src="ascx/footer.ascx" %>
<script language="vb" runat="server">
Sub enter_click(ByVal sender As Object, ByVal e As EventArgs)
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./") & "Qtech/liuxiaohuidata.mdb")
Dim strSql As String
strSql = "Insert into News(Title,Autor,Original,Updatatime,Content) Vaules('" & Title.Text & "','" & Autor.Text & "', '" & Original.Text & "',#" & Now() & "#, '" & Content.Text & "')"
Dim cmd As New OleDbCommand(strSql, conn)
conn.Open() '打开数据库
cmd.ExecuteNonQuery()
conn.Close() '关闭数据库
End Sub
</script>
<html>
<body>
<head>
<title>新闻添加页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb231">
<link href="style.css" type="text/css" rel="Stylesheet" />
</head>
<mynews:top ID="top" runat="server" />
<center>
<form runat="server">
<table border="1" cellpadding="2" cellspacing="0" style="width: 52%" bordercolor=" #6595d6">
<tr>
<td style="width: 148px">
新闻题目</td>
<td>
<asp:TextBox ID="Title" runat="server" />
<asp:RequiredFieldValidator ID="RegularExpressionValidator2" ControlToValidate="Title"
ErrorMessage="必须输入新闻题目" Display="Static" runat="server" /></td>
</tr>
<tr>
<td style="width: 148px">
作者</td>
<td>
<asp:TextBox ID="Autor" runat="server" />
<asp:RequiredFieldValidator ID="RegularExpressionValidator3" ControlToValidate="Autor"
ErrorMessage="必须输入新闻作者" Display="Static" runat="server" /></td>
</tr>
<tr>
<td style="width: 148px">
来源</td>
<td>
<asp:TextBox ID="Original" runat="server" />
<asp:RequiredFieldValidator ID="RegularExpressionValidator4" ControlToValidate="Original"
ErrorMessage="必须输入新闻来源" Display="Static" runat="server" /></td>
</tr>
<tr>
<td style="width: 148px">
新闻内容</td>
<td>
<asp:TextBox ID="Content" TextMode="MultiLine" Columns="5" runat="server" Width="442px" />
<asp:RequiredFieldValidator ID="RegularExpressionValidator6" ControlToValidate="Content"
ErrorMessage="必须输入新闻内容" Display="Static" runat="server" /></td>
<td>
</tr>
</table>
<asp:Button ID="center" Text="提交" OnClick="enter_click" runat="server" />
</form>
</center>
<mynews:footer ID="End1" runat="server" />
</body>
</html>
以上代码可以运行,但是一提交表单就会出错,insert语句是没有问题的吧,以下是详细的错误;
INSERT INTO 语句的语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
源错误:
行 13: Dim cmd As New OleDbCommand(strSql, conn)
行 14: conn.Open() '打开数据库
行 15: cmd.ExecuteNonQuery() (这就是错误的地方)
行 16: conn.Close() '关闭数据库
行 17:
源文件: D:\ASP.NET\课程设计\addnews.aspx 行: 15
堆栈跟踪:
[OleDbException (0x80040e14): INSERT INTO 语句的语法错误。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +177
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +194
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +56
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +105
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +88
ASP.addnews_aspx.enter_click(Object sender, EventArgs e) in D:\ASP.NET\课程设计\addnews.aspx:15
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
--------------------编程问答-------------------- 红色的部分应该是values
strSql = "Insert into News(Title,Autor,Original,Updatatime,Content) Vaules('" & Title.Text & "','" & Autor.Text & "', '" & Original.Text & "',#" & Now() & "#, '" & Content.Text & "')"
--------------------编程问答-------------------- 是,是。哎。太粗心了,刚才还以为是什么权限设置的问题。。谢谢你。。。 --------------------编程问答-------------------- 刚才。改过来了。。可以运行。
补充:.NET技术 , VB.NET