开发者

Internationalization and parameterized queries

开发者 https://www.devze.com 2023-04-12 02:30 出处:网络
I make a DataSet and DataTable in C# and then make a report for a SQL Server DB (I Use Report Viewer).

I make a DataSet and DataTable in C# and then make a report for a SQL Server DB (I Use Report Viewer). I need to search Value field in DataBase when my Value is English Like "test" every thing is be OK, but when my value is Arabic\Persian\Farsi the report viewer开发者_C百科 dosen't show me anything.

My query is this:

SELECT DetailsProducts.DarSad, Materials.Material, Products.Product
FROM DetailsProducts INNER JOIN
    Materials ON DetailsProducts.MaterialID = Materials.ID INNER JOIN
    Products ON DetailsProducts.ProductID = Products.ProductID
WHERE (Products.Product = @Product)

When I need one value I can use this query:

SELECT DetailsProducts.DarSad, Materials.Material, Products.Product
FROM DetailsProducts INNER JOIN
    Materials ON DetailsProducts.MaterialID = Materials.ID INNER JOIN
    Products ON DetailsProducts.ProductID = Products.ProductID
WHERE (Products.Product =N'بطری') //(Bottle = بطری)

It is OK, but this " N'exp' " dose not work when I Use Parameters. How can I fix this?


Try to create your parameter with SqlDbType equal to SqlDbType.NVarChar:

SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@Product";
parameter.SqlDbType = SqlDbType.NVarChar;
parameter.Direction = ParameterDirection.Input;
parameter.Value = "بطری";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号