sql查询中的Incorect语法 [英] Incorect syntax in sql query
问题描述
假设我已输入
这是说明。评估的。在Asp.net的文本区域控制中
然后使用以下查询
插入到演示值中( '这是描述。评估。')
它在s附近给出错误的语法错误。我应该如何处理撇号。
评估这会导致插入表格时出错
可以你请建议我
谢谢
suppose i have entered
This is Description. Assessment's. in text area control of Asp.net
& then uses below query
insert into demo values('This is Description. Assessment's. ')
It gives error incorrect syntax near s. How should i deal with apostrophe s .
Assessment's This cause the error while inserting into tabel
Could you please suggest me
thanks
推荐答案
你究竟如何处理这个问题取决于你究竟是什么做:如果你通过SQL Sever Management Studio直接输入,那么只需加倍报价:
Exactly how you deal with this depends on exactly what you are doing: if you are entering this directly via SQL Sever Management Studio then just double up the quotes:
INSERT INTO demo VALUES('This is Description. Assessment''s. ')
(你应该列出你想插入的字段名称 - 它可以帮助防止错误稍后)
但是,如果您是通过VB或C#中的代码执行此操作,那么您真的应该使用参数化查询来执行插入,它将会为你排序。 (将字符串连接起来构成SQL查询非常危险 - 它会让您对SQL注入攻击持开放态度,这可能会损坏或破坏您的数据库。)
(You should list the field names you are trying to insert into though - it can help prevent errors later)
However, if you are doing this via code from VB or C# for example, then you really should use a parameterized query to do the insert, and it will sort it out for you. (Concatenating strings to form an SQL query is very dangerous - it leaves you wide open to an SQL Injection Attack, which could damage or destroy your database).
使用双撇号: -
插入演示值('这是描述。评估'。')
Use Double apostrophe:-
insert into demo values('This is Description. Assessment''s. ')
你可以这样: -
U can utry this:-
DECLARE @val varchar(100)
SET @val='This is Description. Assessment''s.'
INSERT into demo(column_name)
VALUES(@val)
希望,这会对你有帮助......
Hope, this will help you...
这篇关于sql查询中的Incorect语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!