使用转发器的ASP.net SQL查询问题
|
这是我在存储过程中的查询。我正在使用中继器来显示信息。问题是如果我搜索说
Ename = Jim ELocation =史密斯中心
ECity =亚特兰大
通过查询生成器,我得到了两个与之匹配的结果。但是,当我将数据源绑定到转发器并添加参数时,然后尝试运行查询,我的转发器为空。变量是从文本框控件传入的。另外,如果我只传递一个变量,例如标题,它就可以正常工作。但是,当我尝试传递两个或多个变量时,我什么也没得到。任何人对做什么有任何想法?
@title varchar(150),
@venue varchar(150),
@city varchar(100),
@state varchar(50),
@country varchar(100),
@desc varchar(150),
@date smalldatetime = null
AS
SELECT EID, EName, EDate, EDEnd, ELocation, ECity, EState, EDesc, EWebsite
FROM esc
WHERE (@title IS NULL OR EName LIKE \'%\' + @title + \'%\')
AND (@venue IS NULL OR ELocation LIKE \'%\' + @venue + \'%\')
AND (@city IS NULL OR ECity LIKE \'%\' + @city + \'%\')
AND (@state IS NULL OR EState LIKE \'%\' + @state + \'%\')
AND (@country IS NULL OR ECountry = @country)
AND (@desc IS NULL OR EDesc LIKE \'%\' + @desc + \'%\')
AND (@date IS NULL OR EDate = @date)
单击按钮时的简明代码。:
SqlConnection conn = null;
try
{
conn = new SqlConnection(\"\");
SqlCommand command = new SqlCommand();
command.Connection = conn;
command.CommandText = \"seesc\";
command.CommandType = CommandType.StoredProcedure;
SqlParameter title = new SqlParameter();
title.ParameterName = \"@title\";
title.SqlDbType = SqlDbType.VarChar;
title.Direction = ParameterDirection.Input;
title.Value = TitleTextBox.Text;
//other parameters declared here
command.Parameters.Add(title);
//other parameters added here
conn.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
evrep.DataSource = reader;
evrep.DataBind();
}
}
catch { }
没有找到相关结果
已邀请:
1 个回复
傻零凰死授
应该
另外什么时候
使用参数不会为null,但其值为空字符串。那会失败的条件