如何编写带有忽略大小写敏感参数的存储过程

发布于 2024-12-12 12:36:14 字数 1246 浏览 0 评论 0原文

你能告诉我这个有什么问题吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

攀登最高峰 2024-12-19 12:36:14

这一点:

UPPER('%' +'@basharf'+ '%')

您正在连接三个字符串,因此该表达式等于:

UPPER('%@basharf%')

您可能的意思是:

'%' + UPPER(@basharf) + '%'

它将传入的参数与 % 符号连接起来。

This bit:

UPPER('%' +'@basharf'+ '%')

You are concatenating three strings, so this expression is equal to:

UPPER('%@basharf%')

You probably mean:

'%' + UPPER(@basharf) + '%'

Which concatenates the passed in parameter with the % signs.

月亮坠入山谷 2024-12-19 12:36:14

没有方便的 DBMS 来检查这一点,但我认为您需要将 % 放在 UPPERLOWER 函数之外。

就像这样:

'%' + UPPER(@basharf) + '%'

更新

谷歌搜索 SqlDataAdapter 让我认为你正在使用 C#。我不熟悉该数据库 API,因此无法提供任何帮助。然而,作为一般故障排除提示,我建议在尝试从 GUI 代码中运行查询之前,仅​​针对数据库正确获取查询。

Don't have a DBMS handy to check this, but I think you'll want to put the % outside of the UPPER and LOWER functions.

Like so:

'%' + UPPER(@basharf) + '%'

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.

遗弃M 2024-12-19 12:36:14

感谢回答我问题的人,但我想我找到了解决方案......

string kelime = TextBox1.Text;
        char[] oldValue = new char[] { 'i' };
        char[] newValue = new char[] { 'I' };
        for (int sayac = 0; sayac < oldValue.Length; sayac++)
        {
            kelime = kelime.Replace(oldValue[sayac], newValue[sayac]).ToLower();
        }

比,正如您提到的:

SqlDataAdapter dap = new SqlDataAdapter("select adi, birimf, kategori, urunid from urun where (UPPER(adi) like '%' + UPPER(@basharf) + '%') order by kategori", baglanti);
        dap.SelectCommand.Parameters.Add("@basharf", kelime);

Thanks to you people who answered my question but I guess I found the solution...

string kelime = TextBox1.Text;
        char[] oldValue = new char[] { 'i' };
        char[] newValue = new char[] { 'I' };
        for (int sayac = 0; sayac < oldValue.Length; sayac++)
        {
            kelime = kelime.Replace(oldValue[sayac], newValue[sayac]).ToLower();
        }

Than, as you mentioned :

SqlDataAdapter dap = new SqlDataAdapter("select adi, birimf, kategori, urunid from urun where (UPPER(adi) like '%' + UPPER(@basharf) + '%') order by kategori", baglanti);
        dap.SelectCommand.Parameters.Add("@basharf", kelime);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文