J
Jeff
Hi,
I have been trying to load my dataTable in my database for 2 days
without any success. Any help would be appreciated.
INFO:
1- I am using OleDb.
2- I have a DataTable that I created manually from an array.
3- I also have a database with a table containing the exact same
column as the dataTable.
4- When I execute the following code I get an error saying: "Update
unable to find TableMapping['Table'] or DataTable 'Table'." I don't
understand why I would need mapping where both tables are identical.
5- All the example I found were where they initially pulled info from
the database first then update the database with changes. I didn't
find anything where you make your own datatable then update an
existing database.
I guess I must be forgetting something stupid, but before I jump from
window I thought I'd ask. ( don't worry I live on the main floor! )
thanks for your wisdom,
jf
CODE:
public void makeTable(DataTable dt, string tableName)
{
OleDbConnection conn = new OleDbConnection();
DataSet dset = new DataSet(tableName); //create the data set
dset.Tables.Add(dt); //add to collection
conn = db.getConnection();
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbDataAdapter myDataAdapter =
new OleDbDataAdapter("Select * from " +
tableName, conn);
//open the table
OleDbCommandBuilder olecb = new OleDbCommandBuilder(myDataAdapter);
myDataAdapter.Fill(dset, tableName);
try
{
myDataAdapter.Update(dset); //THIS LINE THROW ERROR!!!
conn.Close();
}
catch (Exception e)
{
Console.WriteLine (e.Message);
}
}
I have been trying to load my dataTable in my database for 2 days
without any success. Any help would be appreciated.
INFO:
1- I am using OleDb.
2- I have a DataTable that I created manually from an array.
3- I also have a database with a table containing the exact same
column as the dataTable.
4- When I execute the following code I get an error saying: "Update
unable to find TableMapping['Table'] or DataTable 'Table'." I don't
understand why I would need mapping where both tables are identical.
5- All the example I found were where they initially pulled info from
the database first then update the database with changes. I didn't
find anything where you make your own datatable then update an
existing database.
I guess I must be forgetting something stupid, but before I jump from
window I thought I'd ask. ( don't worry I live on the main floor! )
thanks for your wisdom,
jf
CODE:
public void makeTable(DataTable dt, string tableName)
{
OleDbConnection conn = new OleDbConnection();
DataSet dset = new DataSet(tableName); //create the data set
dset.Tables.Add(dt); //add to collection
conn = db.getConnection();
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbDataAdapter myDataAdapter =
new OleDbDataAdapter("Select * from " +
tableName, conn);
//open the table
OleDbCommandBuilder olecb = new OleDbCommandBuilder(myDataAdapter);
myDataAdapter.Fill(dset, tableName);
try
{
myDataAdapter.Update(dset); //THIS LINE THROW ERROR!!!
conn.Close();
}
catch (Exception e)
{
Console.WriteLine (e.Message);
}
}