I have a DataTable with about 6000 rows created from a query to SQL Server DB. Now I try to add the data into a MS-Access table. Everything seems to work. No exceptions are raised but no data is a being added. Here is the code I'm using:
DataTable t = new DataTable();
// fill data table
// Create DB - works!
var Name = DateTime.Now.ToString("H_mm_ss");
string strAccessConnectionString = @"Provider = Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=" + "C:\\chhenning\\" + Name + ".mdb;";
ADOX.CatalogClass Catalog = new ADOX.CatalogClass();
Catalog.Create(strAccessConnectionString);
OleDbConnection accessConnection = new OleDbConnection(strAccessConnectionString);
accessConnection.Open();
// Create Table - works!
OleDbCommand Command = accessConnection.CreateCommand();
Command.CommandText = "Create Table Test( "
+ " ID_ int not null "
+ " , Year_ int not null "
+ " , Value_ float not null )";
Command.ExecuteNonQuery();
// Add data into table - does not work!
var adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand("select * from Test", accessConnection);
var cbr = new OleDbCommandBuilder(adapter);
cbr.GetInsertCommand();
var Rows = adapter.Update(t);
I have made sure that my DataTable has data in and that both the DataTable and MS-Access have the same columns with the same data types.
Can someone spot what wrong with code? What are the steps I do to investigate the problem further?