日期:2014-05-19  浏览次数:20477 次

为什么改成这样了还是不行呢,还是说INSERT语句错误?
后台数据库是access,望高手再帮忙指点一下哦
OleDbConnection   con=new   OleDbConnection   ();
con.ConnectionString   =ConfigurationSettings.AppSettings   [ "ConnectionString "];
OleDbCommand   cmd=new   OleDbCommand   ();
cmd.CommandText   = "Insert     into   book(姓名,地址,联系电话,E-MAIL,QQ号码) ";  
        cmd.CommandText   += "Values( ' "+   this.name.Text   +   " ', ' "   +   this.dress.Text   +   " ', ' "   +   this.phone.Text+   " ', ' "   +   this.mail   .Text   +   " '   , ' "   +   this.qq.Text   + " '   ) ";
cmd.Connection   =con;
                                con.Open();
cmd.ExecuteNonQuery   ();    
        //this.Response   .Write   (cmd.CommandText   );
con.Close();

------解决方案--------------------
语句中Values前面没有空格
------解决方案--------------------
依依秋寒回答:

改成如下即可!
cmd.CommandText = "Insert into book ([姓名],[地址],[联系电话],[E-MAIL],[QQ号码]) ";
cmd.CommandText += " Values( ' "+ this.name.Text + " ', ' " + this.dress.Text + " ', ' " + this.phone.Text + " ', ' " + this.mail .Text + " ' , ' " + this.qq.Text + " ' ) ";
------解决方案--------------------
你调试一下,把语句复制到数据库中运行看看是什么错误啊,这样大家很难看出来的!
------解决方案--------------------
([姓名],[地址],[联系电话],[E-MAIL],[QQ号码]) 为什么这么弄啊!~
------解决方案--------------------
values前面没有空格,另外尽量使用参数传递方式拼写sql,最好写成存储过程,很多公司都这么要求不容易出错
------解决方案--------------------
最好不要用中文做字段名
------解决方案--------------------
values前面没有空格
cmd.CommandText = "Insert into book(姓名,地址,联系电话,E-MAIL,QQ号码) ";
cmd.CommandText += " Values( ' "+ this.name.Text + " ', ' " + this.dress.Text + " ', ' " + this.phone.Text+ " ', ' " + this.mail .Text + " ' , ' " + this.qq.Text + " ' ) ";