在SQL Server 2005中插入查询单引号和双引号 [英] Single and double quotes in Sql Server 2005 insert query

查看:141
本文介绍了在SQL Server 2005中插入查询单引号和双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有在地址文本框,单引号和双引号我。怎么可以插入到数据库中。我使用SQL2005。
我的code是如下...

 海峡=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 +';

地址是乔HN的房子

其文本展示台如下:......

  EXEC sp_cust_regC7,乔治·约瑟夫','男','0001-212123,乔HN的房子','515151','04862787896','8888888888 ','johnyqw @ gmail.com','N'

我用

  SQL字符串= str.Replace(\\',);

然后我得到

  EXEC sp_cust_reg C7,乔治·约瑟夫,男,0001-212123,JOHN家,515151,04862787896,8888888888,johnyqw@gmail.com,N


解决方案

您逃离

因此​​,而不是 str.Replace(\\',)使用 str.Replace(','' )

There is single and double quotes in the address textbox .How can I insert into database. I am using SQL2005. My code is as follows...

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 + "'";

Address is jo"hn's house

Its Text Visualizer is as follows...

exec sp_cust_reg 'C7','George Joseph','Male','0001-212123','jo"hn's house','515151','04862787896','8888888888','johnyqw@gmail.com','N'

I used

string sql = str.Replace("\'", " ");.

Then I get

exec sp_cust_reg  C7 , George Joseph , Male , 0001-212123 , jo"hn s house , 515151 , 04862787896 , 8888888888 , johnyqw@gmail.com , N 

解决方案

You escape ' as ''.

So instead of str.Replace("\'", " ") use str.Replace("'", "''")

这篇关于在SQL Server 2005中插入查询单引号和双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆