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#
rupesh asked 2 weeks 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
Jyoti answered 2 weeks ago
Your Answer

19 + 20 =

Popular Tags

WP Facebook Auto Publish Powered By :