日期:2014-05-18  浏览次数:20419 次

asp.net向access数据库提交记录的问题(急)
OleDbConnection conn = new OleDbConnection(DAL.dbConnection);
conn.Open();
OleDbCommand comm = new OleDbCommand();
comm.Connection = conn;
comm.CommandType = CommandType.Text;
comm.CommandText = "insert into mem_mas( MemName,RealName,Password,Sex,GroupID,GroupName,Company,Address,ZipCode,Telephone,Fax,Mobile,Email,HomePage,Working)" +" values ('" + this.MemName.Text + "','" + this.RealName.Text + "','" + this.Password.Text +"','" + this.getSex() + "','" + this.GroupID.SelectedValue + "','" + this.getGroupNameSi() + "','" + this.Company.Text + "','" + this.Address.Text + "','" + this.ZipCode.Text +"','" + this.Telephone.Text + "','" + this.Fax.Text + "','" + this.Mobile.Text + "','" + this.Email.Text + "','" + this.HomePage.Text + "'," + this.ViewFlagSi.Checked + ") ";
comm.ExecuteNonQuery();

向数据库提交记录的代码。

在程序里执行到comm.ExecuteNonQuery();这一句的时候总是提示insert into 语句的语法错误。

但是我把这段sql拷贝到access数据库的sql视图里执行的时候却没有错误,数据也能正常加入,这是怎么回事???

------解决方案--------------------
你断点跟一下那个commandText看看有什么错误啊,这么多不好说的。。
------解决方案--------------------
insert into mem_mas( MemName,RealName,Password,Sex,GroupID,GroupName,Company,Address,ZipCode,Telephone,Fax,Mobile,Email,HomePage,Working)" +" values 

最后的那个+号 多余了 去掉

改为


comm.CommandText = "insert into mem_mas( MemName,RealName,Password,Sex,GroupID,GroupName,Company,Address,ZipCode,Telephone,Fax,Mobile,Email,HomePage,Working) values ('" + this.MemName.Text + "','" + this.RealName.Text + "','" + this.Password.Text +"','" + this.getSex() + "','" + this.GroupID.SelectedValue + "','" + this.getGroupNameSi() + "','" + this.Company.Text + "','" + this.Address.Text + "','" + this.ZipCode.Text +"','" + this.Telephone.Text + "','" + this.Fax.Text + "','" + this.Mobile.Text + "','" + this.Email.Text + "','" + this.HomePage.Text + "'," + this.ViewFlagSi.Checked + ") ";
------解决方案--------------------
看一下comm.CommandText的内容然后拿到你得查询分析器里执行一下
------解决方案--------------------
我建议你在SQL语句的字段中加入[]试一下。我以前碰到过的。
------解决方案--------------------
1. password是关键字,请用 [Password]
------解决方案--------------------
高歌的回答总是即经典又实用!!
------解决方案--------------------
顶楼上的
------解决方案--------------------
不错 不错。。