Bug related to ColumnName with DataTable.

  • Thread starter William F. Robertson, Jr.
  • Start date
W

William F. Robertson, Jr.

Either this is a bug, or it should be.

DataTable table = new DataTable();

table.Columns.Add( "Base1", typeof( string ) );
table.Columns.Add( "Base2", typeof( string ) );

//these will not run
Trace.Assert( table.Columns["Base1"] != null, "Base1 is null" );
Trace.Assert( table.Columns["Base2"] != null, "Base2 is null" );
Trace.Assert( table.Columns["base1"] != null, "base1 is null" );
Trace.Assert( table.Columns["base2"] != null, "base2 is null" );

table.Columns["Base1"].ColumnName = "newBase1";

//this will not display
Trace.Assert( table.Columns["newBase1"] != null, "newBase1 is null" );
//this will display
Trace.Assert( table.Columns["newbase1"] != null, "newbase1 is null" );

It seems the columns lose their case insensitivity when the ColumnName is
changed.

However the work around we came up with:

DataTable table = new DataTable();

table.Columns.Add( "Base1", typeof( string ) );
table.Columns.Add( "Base2", typeof( string ) );

table.Columns["Base1"].ColumnName = "newBase1";

//this will run
Trace.Assert( table.Columns["newbase1"] != null, "newbase is null" );
table = table.Clone();

//this will not run. The case insensitive is working again.
Trace.Assert( table.Columns["newbase1"] != null, "newbase is null" );

------
Is this the work around we should be doing? Is there another way? Is this
even a bug or am I missing something here?

Thanks,

bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top