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

C# 使用带参数的动态查询,当数据为阿拉伯语时,选择查询不起作用,c#,mysql,asp.net,C#,Mysql,Asp.net,在Visual studio内部的asp.net c代码中,我开发了一个搜索按钮。当我尝试运行代码时,它在编写代码时不会返回任何内容。我认为问题在于统计表是用阿拉伯语写的 SqlParameter[] para = new SqlParameter[4]; para[0] = new SqlParameter("@stat_leger", ddlACCcode.SelectedValue); para[1] = new SqlParameter("@branch", DDLBra

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

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中编写相同的select时,它起到了作用。但在阿拉伯语中,我使用了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);

我想可能是这样的:

para[0] = new SqlParameter("@stat_leger", "N'"+ddlACCcode.SelectedValue+"'")
然后使用asp.net中的查询:

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);

然后,建议您打印最终的SQL命令,以查看它是否与SQL命令的正确形式匹配

检查字段或表的字符集。使用引号。。。