在sql查询中有什么问题 [英] what is problem with 's in sql query

查看:76
本文介绍了在sql查询中有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有评论文本框。它工作得很完美。当我在数据库表中成功插入的评论数据的文本框中输入文本。但是如果我在文本框中使用's'写评论,它会给我错误。我知道完全是错误,因为's。需要什么编码来解决这个问题?

i have comment textbox.And it is working perfectly.when i enter text in textbox of comment data inserted sucessfully in database table.But if i use ''s in writing comment in textbox,it will give me error.I know perfectly that it is error because of ''s.what coding is require to solve this problem?

SqlCommand cmd = new SqlCommand("insert into table (name,address,comment) values(''" + txtname.text + "'',''" + txtaddress.text + "'',''"+txtcomment.text+"'')", cnn);

推荐答案

基本上,你需要加倍。



尝试类似:



Basically, you need to double it up.

Try something like:

txtcomment.Text.Replace("'", "''");





这是非常简单的,你应该研究这背后的原因,并提出一个解决方案f它的具体需求。



That is very simplistic and you should research the reasons behind this and come up with a solution that fits your specific needs.


这篇关于在sql查询中有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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