문제

My C# Console Applcation:

1:

string CE_ParentName_ = CEReader5[0].ToString(); // get string with lithuanian letters for example "Konsolės". 

if I use Console.WriteLine() , I get correct output in console.

2:

readname.CommandText = "SELECT [ID] FROM [Net7].[dbo].[GroupFilter] WHERE 
[GroupFilterName]='" + CE_ParentName_ + "'"; // I need to find records in my DB with name of that string (1 possible option)

3:

if (NameReader.Read()) { idd = NameReader[0].ToString(); } // if i get any results ar no.2 i need to read them

The point is that no.2 returns zero results if string contains lithuanian letters. If string is w/o lithuanian letters - everything works perfect. Tried everything, you are my last hope folks.

도움이 되었습니까?

해결책

Are Lithuanian characters multibyte? (like Japanese for example) Is the GroupFilterName NVARCHAR or VARCHAR? If it's NVARCHAR, perhaps you need to put N in front of the string.

Eg.

readname.CommandText = "SELECT [ID] FROM [Net7].[dbo].[GroupFilter] WHERE 
[GroupFilterName]=N'" + CE_ParentName_ + "'";

And see asawyer's comment regarding avoiding injection attacks.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top