I'm really inexpert in database and OLE stuff, but I've managed to find (after a ton of searchng) enough explanation to write GetDataTable and UpdateDataTable functions.
My question is: Have I missed something here below which will bite me in the future?
public static void UpdateDataTable (DataTable dt)
{
try
{
OpenDbConnections();
string strSQL = "SELECT * FROM " + dt.TableName;
OleDbDataAdapter myCmd = new OleDbDataAdapter(strSQL, m_DbDataConnection);
OleDbCommandBuilder myCmdBuilder = new OleDbCommandBuilder(myCmd);
myCmdBuilder.GetInsertCommand(); // So dt.Add works
myCmdBuilder.GetDeleteCommand(); // So a dt row.Delete works
myCmdBuilder.GetUpdateCommand(); // so a dt row.BeginEdit and row.EndEdit works
myCmd.Update(dt);
}
catch (Exception Ex)
{
ABSup.Log.WriteLn(CLog.Type_e.ekErr, "UpdateTable failed <" + dt.TableName + ">\n" +
Ex.Message, "\n", ABSup.m_sTableDBFullFilename,
"\nHRESULT:", Ex.HResult.ToString());
}
}
// Get a named table from the database...
// Tables are normally in DB_CreaColl.mdb
public static DataTable GetDataTable (string sTableName)
{
try
{
OpenDbConnections();
string strSQL = "SELECT * FROM " + sTableName;
OleDbDataAdapter myCmd = new OleDbDataAdapter(strSQL, m_DbDataConnection);
DataSet dtSet = new DataSet();
myCmd.Fill(dtSet, sTableName);
DataTable tabData = dtSet.Tables[0];
return tabData;
}
catch (Exception Ex)
{
ABSup.Log.WriteLn(CLog.Type_e.ekErr, "GetDataTable could not open <" + sTableName + ">\n" +
Ex.Message, "\n", ABSup.m_sTableDBFullFilename,
"\nHRESULT:", Ex.HResult.ToString());
return null;
}
}
PS: I've also tried to add the above code in the 101010 code window, but it does not work...