相关疑难解决方法(0)

Sql Server 2005插入查询中的单引号和双引号

地址文本框中有单引号和双引号.如何插入数据库.我正在使用SQL2005.我的代码如下......

str = "exec sp_cust_reg '" + customer.Cust_Id + "','" + customer.Cust_Name + "','" + customer.Gender + "','" + customer.Acc_no + "','" + customer.Address + "','" + customer.Pin_no + "','" + customer.Phone_no + "','" + customer.Mobile_no + "','" + customer.Email + "','" + customer.Authorise + "'";
Run Code Online (Sandbox Code Playgroud)

地址是jo"hn's house

它的Text Visualizer如下......

exec sp_cust_reg 'C7','George Joseph','Male','0001-212123','jo"hn's house','515151','04862787896','8888888888','johnyqw@gmail.com','N'
Run Code Online (Sandbox Code Playgroud)

我用了

string sql = str.Replace("\'", " ");.
Run Code Online (Sandbox Code Playgroud)

然后我明白了

exec sp_cust_reg  C7 , George Joseph , Male , 0001-212123 , jo"hn s house , 515151 , …
Run Code Online (Sandbox Code Playgroud)

c# sql-server asp.net sql-server-2005

-1
推荐指数
1
解决办法
2116
查看次数

标签 统计

asp.net ×1

c# ×1

sql-server ×1

sql-server-2005 ×1