c# - 当数据为阿拉伯语时,选择查询不起作用,使用带参数的动态查询

标签 c# mysql asp.net

Visual studio内的asp.net c#代码中,我开发了一个搜索按钮。当我尝试运行代码时,它在编写代码时不返回任何内容。我认为问题在于 stat_leger 是用阿拉伯语编写的。

SqlParameter[] para = new SqlParameter[4];
    para[0] = new SqlParameter("@stat_leger", ddlACCcode.SelectedValue);
    para[1] = new SqlParameter("@branch", DDLBranch.SelectedValue);
    para[2] = new SqlParameter("@from", db.getDate(txtFrom.Text));
    para[3] = new SqlParameter("@to", db.getDate(txtTo.Text));

 DataTable dtreport = db.SelectCmdText("Select * from PostedVoucher join transactions on trans_code = stat_trans_code where stat_leger = @stat_leger and branch=@branch and stat_date between @from and @to ORDER BY stat_date ", para);

GridView1.DataSource = dtreport;
GridView1.DataBind();
float GTotal = 0;
float GTotalcrd = 0;
float GTotaldeb = 0;

当我尝试在 sql server 中编写相同的选择时,它起作用了。但对于阿拉伯语,我使用了 N ,它是返回记录。

   Select * from PostedVoucher join transactions on trans_code =     
    stat_trans_code 
      where stat_sub_leger = N'الصندوق' and branch= N'الفرع الرئيسي' and stat_date between '2013-12-05 00:00:00.000' AND '2013-12-05 00:00:00.000' ORDER BY stat_date ;

我尝试将其写入 select as 但仍然不起作用:

          DataTable dtreport = db.SelectCmdText("Select * from PostedVoucher join transactions on trans_code = stat_trans_code where stat_sub_leger = N'@stat_sub_leger' and branch=@branch and stat_date between @from and @to ORDER BY stat_date ", para);

最佳答案

尝试更改您的查询,例如:

Select * from PostedVoucher join transactions on trans_code = stat_trans_code where stat_leger like '%' + @stat_leger + '%' OR  branch like '%' + @branch + '%' AND stat_date between @from and @to ORDER BY stat_date ", para);

关于c# - 当数据为阿拉伯语时,选择查询不起作用,使用带参数的动态查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28806344/

相关文章:

php - 连接外部Mysql数据库

.net - ASP.NET 中的 Web 服务器回调 Web 浏览器客户端机制

c# - 第一次在 ASP.NET 中使用安全性

javascript - 如何在azure网站子目录中运行node.js应用程序

c# - 在 Linq To SQL 中转换

c# - 如何使用 C# 部署 Helm 3 图表

c# - 如何在 blazor 页面上使用 usermanager?

mysql - MySQL 中的逻辑或

php - 我需要获取通过 AJAX 发送的 $_GET ['loc' ]

c# - 如何使用批处理文件在应用程序外部运行 CodedUI 测试并创建报告