I have a set of data that I am pulling from a database and putting into a datatable. When I assign the datatable to the DataSource of my grid, I get the error: "Key already exists Parameter name: Key"
I have found that two columns in the .Net DataTable have the same name, but different cases. Here is a short example to reproduce this:
1. Add a grid to the form and just click "Finshed" when the wizard comes up.
2. Add the following code:
Dim dt As New DataTable("Test")
Dim col1 As DataColumn = New DataColumn("Col 1", GetType(Double)) col1.Caption = "Col 1" dt.Columns.Add(col1)
Dim col2 As DataColumn = New DataColumn("COL 1", GetType(Double)) col2.Caption = "COL 1" dt.Columns.Add(col2)
UltraGrid1.DataSource = dt ' <--- Exception will occur here
The names of the DataColumns only differ in case. Aside from changing the names (since in the real world I will not have control of this and the names differing in case only is a potential in the data I have to use), is there a setting I am missing to keep this from happening.
No, the column names are not case sensitive, so they must be unique ignoring case, just like any variable name in VB.
Thanks for the response. I know VB variable names are not case sensitive, but I was surprised by this behavior. If you use a keyed collection in the framework, the key values are case sensitive.
Yes, but the grid's Columns collection is not case sensitive. I suppose that it could have been designed that way. But I suspect it was not because the control is written for both C# and VB, and VB programmers may not be used to case sensitive keys.
I solved this problem. The keys were conflicting with the control on the form and some control's base class. I changed the keys and it solved the problem.
Thanks.
Hi,
can you please check the following screen shot:
http://picturepush.com/public/5094946
Can you please tell me what might have gone wrong? I have no idea how to fix this. Thanks!!
..ab
No, there's no way to turn it off.
is there anyway of turning this case sensitivety off?
This is really messing with me becuase of a mix between mssql and oracle..