如何编写带有忽略大小写敏感参数的存储过程
你能告诉我这个有什么问题吗?
ALTER proc [dbo].[UrunuGetir](@basharf nvarchar(5))
as
select adi, urunid, kategori
from urun
where (UPPER(adi) like UPPER('%' +'@basharf'+ '%'))
or (LOWER(adi) like LOWER ('%' +'@basharf'+ '%'))
order by kategori
没有错误,但也没有数据。
这是编辑:
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != null)
{
UrunGetir(TextBox1.Text);
}
else
{
return;
}
}
private void UrunGetir(string p)
{
SqlConnection baglanti = new SqlConnection("....");
SqlDataAdapter dap = new SqlDataAdapter("select adi, urunid, kategori, birimf from urun where (UPPER(adi) like '%' + UPPER(@basharf) + '%' ) or (LOWER(adi) like '%' + LOWER(@basharf) + '%' ) order by kategori", baglanti);
dap.SelectCommand.Parameters.Add("@basharf", p);
if (baglanti.State == System.Data.ConnectionState.Closed)
baglanti.Open();
DataTable dt = new DataTable();
dap.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
if (baglanti.State == System.Data.ConnectionState.Open)
baglanti.Close();
HiddenField1.Value = p.Substring(0,p.Length);
}
Can you please tell me what is wrong with this one?
ALTER proc [dbo].[UrunuGetir](@basharf nvarchar(5))
as
select adi, urunid, kategori
from urun
where (UPPER(adi) like UPPER('%' +'@basharf'+ '%'))
or (LOWER(adi) like LOWER ('%' +'@basharf'+ '%'))
order by kategori
No errors but also no data.
Here is the edit:
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != null)
{
UrunGetir(TextBox1.Text);
}
else
{
return;
}
}
private void UrunGetir(string p)
{
SqlConnection baglanti = new SqlConnection("....");
SqlDataAdapter dap = new SqlDataAdapter("select adi, urunid, kategori, birimf from urun where (UPPER(adi) like '%' + UPPER(@basharf) + '%' ) or (LOWER(adi) like '%' + LOWER(@basharf) + '%' ) order by kategori", baglanti);
dap.SelectCommand.Parameters.Add("@basharf", p);
if (baglanti.State == System.Data.ConnectionState.Closed)
baglanti.Open();
DataTable dt = new DataTable();
dap.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
if (baglanti.State == System.Data.ConnectionState.Open)
baglanti.Close();
HiddenField1.Value = p.Substring(0,p.Length);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这一点:
您正在连接三个字符串,因此该表达式等于:
您可能的意思是:
它将传入的参数与
%
符号连接起来。This bit:
You are concatenating three strings, so this expression is equal to:
You probably mean:
Which concatenates the passed in parameter with the
%
signs.没有方便的 DBMS 来检查这一点,但我认为您需要将
%
放在UPPER
和LOWER
函数之外。就像这样:
更新
谷歌搜索
SqlDataAdapter
让我认为你正在使用 C#。我不熟悉该数据库 API,因此无法提供任何帮助。然而,作为一般故障排除提示,我建议在尝试从 GUI 代码中运行查询之前,仅针对数据库正确获取查询。Don't have a DBMS handy to check this, but I think you'll want to put the
%
outside of theUPPER
andLOWER
functions.Like so:
Update
Googling
SqlDataAdapter
makes me think you're using C#. I'm not familiar with that database API, so I can't offer any help there. However, as a general troubleshooting tip, I would recommend getting the query correct against the database alone before trying to run it from within your GUI code.感谢回答我问题的人,但我想我找到了解决方案......
比,正如您提到的:
Thanks to you people who answered my question but I guess I found the solution...
Than, as you mentioned :