首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

为什么改成这样了还是不行呢,还是说INSERT语句异常

2012-01-26 
为什么改成这样了还是不行呢,还是说INSERT语句错误?后台数据库是access,望高手再帮忙指点一下哦OleDbConne

为什么改成这样了还是不行呢,还是说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 + " ' ) ";

热点排行