Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用c语言存储过程过滤datagrid中基于文本框的记录#_C#_Search_Stored Procedures - Fatal编程技术网

C# 用c语言存储过程过滤datagrid中基于文本框的记录#

C# 用c语言存储过程过滤datagrid中基于文本框的记录#,c#,search,stored-procedures,C#,Search,Stored Procedures,我想根据文本框过滤datagrid上的行,我使用的是一个存储过程。我的代码如下: 我在存储过程中编写了用于选择的查询: if @operation =1 select * from Item_Configuration where itemId like '%' + itemId + '%' C#代码是 private void btnSrch\u单击(对象发送方,事件参数e) { SqlConnection conn1=新的SqlConnection(); 尝试 { SqlCommand s

我想根据文本框过滤datagrid上的行,我使用的是一个存储过程。我的代码如下:

我在存储过程中编写了用于选择的查询:

if @operation =1
select * from Item_Configuration where itemId like '%' + itemId + '%'
C#代码是

private void btnSrch\u单击(对象发送方,事件参数e)
{
SqlConnection conn1=新的SqlConnection();
尝试
{
SqlCommand selectItem=新的SqlCommand(“项目配置SP”,conn1);
选择Item.CommandType=CommandType.StoredProcess;
如果(itemId.Text==“”)
{
selectItem.Parameters.Add(“@operation”,SqlDbType.VarChar);
选择Item.Parameters[“@operation”]。值=1;
选择item.Parameters.Add(“@itemId”,SqlDbType.VarChar);
选择item.Parameters[“@itemId”].Value=itmId.Text;
SqlDataReader myReader=selectItem.ExecuteReader();
列表=新列表();
while(myReader.Read())
{
if(myReader.HasRows)
{
项目=新项目();
item=MapItem(myReader,item);
列表。添加(项目);
}
}
dataGridView1.DataSource=列表;
}
}
}

现在我在网格上获取所有记录该记录未基于文本框进行过滤我找不到我错在哪里请帮助

鉴于您使用的是Sql Server,您的查询正在运行

而不是这个

select * from Item_Configuration where itemId = '%' + itemId + '%'
一定是

select * from Item_Configuration where itemId LIKE '%' + itemId + '%'

此外,如果您从textbox的输入中获取操作id,则必须添加此项

selectItem.Parameters["@operation"].Value = txtbox.Text.Trim();

这是一个存储过程,就像存储在数据库中一样,与存储无关……是的,稍后我们会处理类似的语句,但它不起作用。如果itemID是文本框的名称,则代码和条件不正确。。您已经使用if(itemId.Text==“”)设置了一个断点,然后检查您的代码流。。。
selectItem.Parameters["@operation"].Value = txtbox.Text.Trim();