asp.net 连接access数据库出现insert into 语法错误
以下是具体代码(asp.net3.5,access2003)----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_register_Click(object sender, EventArgs e)
{
String username = user_name.Text;
String email_ = email.Text;
String pass = password.Text;
String realname = real_name.Text;
String 易做图_ = 易做图.Text;
String qq_ = qq.Text;
String address_ = address.Text;
String website_ = website.Text;
String tel = telphone.Text;
String productid = product_id.Text;
String remark_ = remark.Text;
string sql = "INSERT INTO register (user_name,email,password,real_name,易做图,qq,address,website,telphone,product_id,remark) values ( '" + username + "','"
+ email_ + "','" + pass + "','" + realname + "','" + 易做图_ + "','" + qq_ + "','" + address_ + "','" + website_ + "','" + tel + "','" + productid + "','" + remark_ + "')";
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["mydb"].ToString());
OleDbCommand comm = new OleDbCommand(sql,conn);
comm.Connection.Open();
comm.ExecuteNonQuery();
comm.Connection.Close();
}
}
------------------------错误信息----------------------------------
INSERT INTO 语句的语法错误。说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
源错误:
行 37: OleDbCommand comm = new OleDbCommand(sql,conn); 行 38: comm.Connection.Open(); 行 39: comm.ExecuteNonQuery(); 行 40: 行 41: |
源文件: d:\kiyo\register.aspx.cs 行: 39
堆栈跟踪:
[OleDbException (0x80040e14): INSERT INTO 语句的语法错误。] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1006560 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113 _Default.Button_register_Click(Object sender, EventArgs e) in d:\kiyo\register.aspx.cs:39 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 |
追问:恩,谢谢!!!改了以后,没有提示insert into的错误了。。。但是提示“查询值的数目与目标字段中的数目不同”,是因为我的数据表里id一项是自动生成的,没有填写进来是吗?那要怎么改呢。。。哦,还有,为什么pass要加上【】号呢?