Try to search your question here, if you can't find : Ask Any Question Now ?

very strange string unique issue in C#

HomeCategory: stackoverflowvery strange string unique issue in C#
Avatarrupesh asked 3 months ago

I am using VSTS2008 + C# + .Net 3.0. Here is my code and related exception from ADO.Net. Here is my input two strings in both binary form and text form, any ideas what is wrong? Why the two different strings will be treated as the same by ADO.Net?

Exception message:

An unhandled exception of type 'System.Data.ConstraintException' occurred in System.Data.dll

Additional information: Column 'Name' is constrained to be unique.  Value '������' is already present.

Input strings in binary form and text form:

alt text

alt text

StackOverflow does not display correctly for my code for strings �����, here is screen snapshot for what it actually looks like in my VSTS 2008 editor.

alt text

My code:

    static void Main(string[] args)
        string[] buf = new string[] { "����", "������" };

        CompareInfo ci = System.Globalization.CultureInfo.InvariantCulture.CompareInfo;
        ci.Compare(buf[0], buf[1], CompareOptions.IgnoreWidth);
        Console.WriteLine (String.Compare(buf[0], buf[1], StringComparison.InvariantCultureIgnoreCase));

        DataTable bulkInserTable = new DataTable("BulkRequestTable");
        bulkInserTable.CaseSensitive = true;
        DataColumn column = null;
        DataRow row = null;

        // add Keyword column to datatable
        column = new DataColumn();
        column.DataType = System.Type.GetType("System.String");
        column.ColumnName = "Name";
        column.ReadOnly = true;
        column.Unique = true;

        foreach (string item in buf)
            row = bulkInserTable.NewRow();
            row["Name"] = item;
1 Answers
Best Answer
AvatarJyoti answered 3 months ago
Your Answer

20 + 0 =

Popular Tags

WP Facebook Auto Publish Powered By :