Click here to Skip to main content
15,904,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
I have a problem with Select Method of DataTable when search Unicode Characters in Asp.Net. DataTable.Select() can't work with Unicode Characters. And Here is My Code........
C#
DataRow[] dr = dt.Select("Name LIKE '%" + txtSearch.Text + "%'");


dt is DataTable and txtSearch.Text Contains Unicode Characters. How can I search Unicode Characters?
Posted

1 solution

If .NET 3.5 or above is used then I think LINQ can be a better alternative as Culture aware comparison can be made with LINQ to get the desired rows from the DataTable.

If .NET 2.0 is to be used then DataTable.Select method is to be used and the DataTable.Select method is not culture aware as reported here
DataTable.Select() method is not culture-aware[^]

A work around for this issue is given here
Problem on DataTable's string comparison [^]
Please see. It may be helpful.
 
Share this answer
 
Comments
Susan Kyaw 14-May-12 0:50am    
Thanks for your answer. I saw this problem is reported as a bug to the Microsoft as you said above. So, I'm in a big trouble because my framework is 2.0 and I can't upgrade project to 3.5. Could anyone kindly help me?
VJ Reddy 14-May-12 2:16am    
Thank you for the response.
Have you tried the alternative given at http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/53536fe1-8df8-44e5-98ac-2429c588376c, given in the solution?
Susan Kyaw 14-May-12 3:40am    
Ya! I copy this code
//
FieldInfo fieldInfo = typeof(DataTable).GetField("_compareFlags", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
fieldInfo.SetValue(table, CompareOptions.OrdinalIgnoreCase, BindingFlags.NonPublic, null, CultureInfo.CurrentCulture);
//
from
http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/53536fe1-8df8-44e5-98ac-2429c588376c (above url)
and paste it in my code before DataTable.Select() Statement.
It works! Both Myanmar Unicode Chars and English Chars can be searched correctly. Thanks a lot for your answer.
VJ Reddy 14-May-12 7:12am    
You're welcome and thank you for accepting the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900