存储过程在linq中进行搜索 [英] stored procedure in linq to search

查看:68
本文介绍了存储过程在linq中进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单中使用组合框,并添加了例如fristName,lastName,age
的项目 我想要当用户使用此项目之一并输入文本框表达式时,填写
datagridview结果查询

我的存储过程:

I use combobox in my form, and add items for example fristName, lastName, age
I want when user one of this item and type in textbox expression,fill
datagridview result query

my stored procedure:

ALTER PROCEDURE dbo.StoredProcedure7
	@orderby as nvarchar(10),@searchText as nvarchar(50)

AS
begin
	select * from Table2
WHERE
 @searchText= 
  CASE @orderby
      WHEN 'frirstName' THEN id2
      WHEN 'lastName' THEN id1 
      WHEN 'age' THEN id3 
  END

end


但是此过程有错误,并且在datagrid中不显示任何内容


当我将nvarchar(max)转换为nvarchar(50)并将此代码用于我的表单时:
dataGridView1.DataSource = dc.StoredProcedure8(comboBox1.SelectedItem.ToString(),texbox.Text);

将nvarchar值"dd"转换为数据类型int时转换失败.


but this procedure has error and doesn''t show anything in datagrid


when i chane nvarchar(max) to nvarchar(50) and use this code to my form:
dataGridView1.DataSource = dc.StoredProcedure8(comboBox1.SelectedItem.ToString(), texbox.Text);

Conversion failed when converting the nvarchar value ''dd'' to data type int.

推荐答案

它的Nvarchar(Max)无法索引. > 您不能在这种情况下使用它.尝试使用其他类型,例如Nvarchar(100).
It''s Nvarchar(Max) it can not be indexed.
You can not use it in the condition. try another type for example Nvarchar(100).


这篇关于存储过程在linq中进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆