PersonalInformation,我想用insert into PersonalInformation values()语句将地址值插入到数据表中,我的写法如下:
insert into PersonalInformation values(...'+this.DropDownList4.SelectedItem.Text+'省'+this.DropDownList5.SelectedItem.Text+'市'',...).我在单引号里面
又嵌套了单引号,不知道这样对不对,如果不对的话,应该怎么改?敬请高手指正!!!
8 个解决方案
#1
字符串两个单引为一个单引。比如:
declare @t varchar(200)
set @t='abcdefg''abcd''efg'
declare @t varchar(200)
set @t='abcdefg''abcd''efg'
#2
莫明奇妙
#3
你最好用参数吧,
SqlCommand cmd = new SqlCommand();
cmd .CommandText = "insert into PersonalInformation values(@province,@city)";
cmd .Connection = con; //这个自己再定义把
string strprovince =this.DropDownList4.SelectedItem.Text+"省";
string strcity=this.DropDownList5.SelectedItem.Text+"市";
cmd.Parameters.AddWithValue("@province",strprovince);
cmd.Parameters.AddWithValue("@city",strcity);
SqlCommand cmd = new SqlCommand();
cmd .CommandText = "insert into PersonalInformation values(@province,@city)";
cmd .Connection = con; //这个自己再定义把
string strprovince =this.DropDownList4.SelectedItem.Text+"省";
string strcity=this.DropDownList5.SelectedItem.Text+"市";
cmd.Parameters.AddWithValue("@province",strprovince);
cmd.Parameters.AddWithValue("@city",strcity);
#4
我只是问我的代码到底对不对?怎么偏偏是这种答非所问的答复,让人着急!!!!!
#5
string InsertSQLString="";
InsertSQLString="insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+"','"+this.DropDownList5.SelectedItem.Text+"市"+"',...)"
然后把InsertSQLString传递给处理方法就可以了
InsertSQLString="insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+"','"+this.DropDownList5.SelectedItem.Text+"市"+"',...)"
然后把InsertSQLString传递给处理方法就可以了
#6
单引号 用\'。你编译一下就知道了。
#7
改成
insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+this.DropDownList5.SelectedItem.Text+"市'',...)
insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+this.DropDownList5.SelectedItem.Text+"市'',...)
#8
错了,多了个单引号
insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+this.DropDownList5.SelectedItem.Text+"市',...)
insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+this.DropDownList5.SelectedItem.Text+"市',...)
#1
字符串两个单引为一个单引。比如:
declare @t varchar(200)
set @t='abcdefg''abcd''efg'
declare @t varchar(200)
set @t='abcdefg''abcd''efg'
#2
莫明奇妙
#3
你最好用参数吧,
SqlCommand cmd = new SqlCommand();
cmd .CommandText = "insert into PersonalInformation values(@province,@city)";
cmd .Connection = con; //这个自己再定义把
string strprovince =this.DropDownList4.SelectedItem.Text+"省";
string strcity=this.DropDownList5.SelectedItem.Text+"市";
cmd.Parameters.AddWithValue("@province",strprovince);
cmd.Parameters.AddWithValue("@city",strcity);
SqlCommand cmd = new SqlCommand();
cmd .CommandText = "insert into PersonalInformation values(@province,@city)";
cmd .Connection = con; //这个自己再定义把
string strprovince =this.DropDownList4.SelectedItem.Text+"省";
string strcity=this.DropDownList5.SelectedItem.Text+"市";
cmd.Parameters.AddWithValue("@province",strprovince);
cmd.Parameters.AddWithValue("@city",strcity);
#4
我只是问我的代码到底对不对?怎么偏偏是这种答非所问的答复,让人着急!!!!!
#5
string InsertSQLString="";
InsertSQLString="insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+"','"+this.DropDownList5.SelectedItem.Text+"市"+"',...)"
然后把InsertSQLString传递给处理方法就可以了
InsertSQLString="insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+"','"+this.DropDownList5.SelectedItem.Text+"市"+"',...)"
然后把InsertSQLString传递给处理方法就可以了
#6
单引号 用\'。你编译一下就知道了。
#7
改成
insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+this.DropDownList5.SelectedItem.Text+"市'',...)
insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+this.DropDownList5.SelectedItem.Text+"市'',...)
#8
错了,多了个单引号
insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+this.DropDownList5.SelectedItem.Text+"市',...)
insert into PersonalInformation values(...'"+this.DropDownList4.SelectedItem.Text+"省"+this.DropDownList5.SelectedItem.Text+"市',...)