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.