请教高手,帮我看一下.
我在做一个通讯录,以下字段是我向数据库添加记录的内容,可运行后添加不进去,说是inset 命令格式不对,请高手指点一下,先行谢过啦
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();
this.Response .Redirect ( "addre.aspx ");
------解决方案--------------------Values( this.name .Text,this.dress .Text ,this.phone .Text,this.mail .Text ,this.qq.Text ) ";错
Values( ' "+this.name .Text+ " ',其他自己改
------解决方案--------------------this.qq.Text 等字符串的两边要加上 " ' " + 文本 + " ' "
------解决方案--------------------Values( this.name .Text,this.dress .Text ,this.phone .Text,this.mail .Text ,this.qq.Text )
这些字段都是varchar类型的吧,那要加 ' ',比如:
"Values( ' " + this.name .Text + " ', " + this.dress .Text + " ') ";
------解决方案--------------------lz其实要学会调试,你在调试状态下就可以得到你要的组合sql语句,这个在查询分析器里面就很清楚错误了