Visual Studio 2008中的SQL查询问题 [英] Problem with SQL query in Visual studio 2008
本文介绍了Visual Studio 2008中的SQL查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在SQL查询中将此代码提供给我的项目,但不起作用:
I give this codes to my project in SQL query but doesn''t work:
SELECT serial, company_name, ..., ...
FROM (table)
WHERE serial like @serial + ''%''
我使用VS 2008和数据库访问2007
I use VS 2008 and database access 2007
推荐答案
串行显然是一个字符串(nvarchar),因此您需要将其放在引号中.
WHERE serial like ''\'' + @serial + ''%''
抱歉,这是用于SQL
在代码中使用
string.format("WHERE serial LIKE ''{0}%''", @serial)
serial is obviously a string(nvarchar) so you need to place it in quotes.
WHERE serial like ''\'' + @serial + ''%''
Sorry, this is for SQL
In code use
string.format("WHERE serial LIKE ''{0}%''", @serial)
您提供的@serial的值是什么.更新您的问题.对我来说语法看起来正确.
对于SQL:
要进行验证,请尝试以下操作:
What is the value of @serial you are providing. Update that in your question. Syntax to me looks correct.
For SQL:
For verification try this if its work fine:
DECLARE @serial varchar(10)
SET @serial = 'A'
SELECT serial, company_name, ..., ...
FROM (table)
WHERE serial like @serial + '%'
对于代码:
For Code:
string serialThatStartWith = "S";
string myQuery = string.format("SELECT serial, company_name FROM (Sometable)WHERE serial LIKE '{0}%'", serialThatStartWith);
请尝试用"将其包围.
Try surround this like with "".
String.Format(" SELECT serial, company_name, ..., ...
FROM (table)
WHERE serial like '{0}%'", serial)
我不知道我是否输入正确,但您应该明白这个想法
I don''t know if i have typed it right but You should get the idea
这篇关于Visual Studio 2008中的SQL查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文