Israel

Israel

  • 701
  • 1.3k
  • 217.2k

Remove a datatable column

Apr 28 2015 11:39 AM
Hi!
 
I wrote this code to try to remove the "FirstName" column. Curiosly, I receive this error. Please could you have a look?
 
 
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Research\Documents\Windows_Application_Samples\Rename_Column_Tablename\WindowsFormsApplication1\App_Data\visa.mdb;Persist Security Info=False");
DataTable table = new DataTable();
table.Columns.Add("name", typeof(int));
table.Columns.Add("function", typeof(string));
table.Columns.Add("date", typeof(DateTime));
table.Columns.Add("FirstName", typeof(string));*/
DataColumn column;
for (int i = 0; i < table.Columns.Count; i++)
{
column = table.Columns[i];
MessageBox.Show(column.ColumnName, i.ToString());
}
table.Columns["FirstName"].SetOrdinal(1);
for (int i = 0; i < table.Columns.Count; i++)
{
column = table.Columns[i];
MessageBox.Show(column.ColumnName, i.ToString());
}
 

Answers (9)