Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top