问题描述
我在sql数据库中搜索xxxx.xxxx之类的字符串,但我没有找回任何值。我的代码是:
SQL存储过程:
Hi,
I am searching for a string like xxxx.xxxx in an sql database, but I don't get back any values. My code is:
SQL Stored Procedure:
ALTER PROCEDURE [dbo].[GetUserId]
-- Add the parameters for the stored procedure here
@Name VarChar
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT *
from dbo.Users
where @Name like ADName
END
ASP.Net代码:
ASP.Net Code:
SqlConnection Connection9 = new SqlConnection(ConfigurationManager.ConnectionStrings["HayConnectionStringTest"].ToString());
SqlCommand SqlCmd9 = new SqlCommand("GetUserId");
SqlCmd9.Connection = Connection9;
SqlCmd9.CommandType = CommandType.StoredProcedure;
SqlCmd9.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar));
SqlCmd9.Parameters["@Name"].Value = valami[1].Trim();//Session["username"];
DataTable DTable9 = new DataTable("DTable");
SqlDataAdapter SqlAdapter9 = new SqlDataAdapter(SqlCmd9);
try
{
Connection9.Open();
SqlAdapter9.Fill(DTable9);
}
catch (Exception ec)
{
Label1.Text = ec.ToString();
}
finally
{
Connection9.Close();
}
如果我对值进行硬编码,则下一个存储过程运行正常。我想我会想念搜索字符串,但我不知道我错在哪里。 THX的帮助,对不起我的英语。
If i hardcode the value, the next stored procedure runs fine. I guess I miss something about searching strings, but I don't know where am I wrong. THX for the helps, and sorry for my english.
推荐答案
ALTER PROCEDURE [dbo].[GetUserId]
-- Add the parameters for the stored procedure here
@Name VarChar(200)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT *
from dbo.Users
where ADName like @Name
SET NOCOUNT OFF;
END
我想你的名字参数需要一些长度要定义的值。另外你的名字与列中存储的名字完全相同,或者你需要可能的名字,那么你必须使用外卡(例如%)。
I guess your name parameter expects some length values to be defined. and additionally do your name is exactly same as stored in column or you need likely names, then you have to use the wild card(e.g %).
这篇关于SQL搜索,没有返回值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!