Hello everyone,
I am using VSTS 2008 + C# + .Net 3.0. I have two input strings, I think they are different. But the following C# code thinks they are the same, and throws System.Data.ConstraintException, says Column Name is contrained to be unique, but value already exists. Any ideas what is wrong?
Here is my code and my input strings,
Hex view of my input strings,
http://i30.tinypic.com/2anx2b.jpg
Notepad view of my input strings,
http://i30.tinypic.com/2q03hn4.jpg
My code,
static void Main(string[] args)
{
string[] buf = new string[] { "2ch", "2ch" };
DataTable bulkInserTable = new DataTable("BulkTable");
DataColumn column = null;
DataRow row = null;
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "Name";
column.ReadOnly = true;
column.Unique = true;
bulkInserTable.Columns.Add(column);
foreach (string item in buf)
{
row = bulkInserTable.NewRow();
row["Name"] = item;
bulkInserTable.Rows.Add(row);
}
}
EDIT 1:
My confusion is, why C# Dictionary thinks they are different, but DataSet thinks they are of the same. Any solution to make the behavior consistent? Here is my code to prove C# Dictionary thinks they are different, the return buf array is of two elements.
Dictionary<string, bool> dic = new Dictionary<string, bool>();
foreach (string s in buf)
{
dic[s] = true;
}
buf = new List<string>(dic.Keys).ToArray(); // we got two strings here, other than one, which proves Dictionary thinks the two strings are different.
thanks in advance, George