ADO.NET Datagrid database caching in VS.NET
// Add a new record to the database directlly
// It is very slow since it is operating to the db without caching
//
public void AddLog(string info)
{
objDatasetLog.LogTable.AddLogTableRow( DateTime.Now, 0, "User", info);
}
//
// Better approach:
//
// Create a cache record, then merge to the real database laterly
//
public void AddLog(string info)
{
// Create a new dataset to hold the records returned from the call to FillDataSet.
// A temporary dataset is used because filling the existing dataset would
// require the databindings to be rebound.
PDFAuto.DatasetLog objDataSetTemp;
objDataSetTemp = new PDFAuto.DatasetLog();
try
{
// Attempt to fill the temporary dataset.
objDataSetTemp.LogTable.AddLogTableRow( DateTime.Now, 0, "User", info);
}
catch (System.Exception eFillDataSet)
{
// Add your error handling code here.
throw eFillDataSet;
}
try
{
grdLogTable.DataSource = null;
// Empty the old records from the dataset.
objDatasetLog.Clear();
// Merge the records into the main dataset.
objDatasetLog.Merge(objDataSetTemp);
grdLogTable.SetDataBinding(objDatasetLog, "LogTable");
}
catch (System.Exception eLoadMerge)
{
// Add your error handling code here.
throw eLoadMerge;
}
}
// It is very slow since it is operating to the db without caching
//
public void AddLog(string info)
{
objDatasetLog.LogTable.AddLogTableRow( DateTime.Now, 0, "User", info);
}
//
// Better approach:
//
// Create a cache record, then merge to the real database laterly
//
public void AddLog(string info)
{
// Create a new dataset to hold the records returned from the call to FillDataSet.
// A temporary dataset is used because filling the existing dataset would
// require the databindings to be rebound.
PDFAuto.DatasetLog objDataSetTemp;
objDataSetTemp = new PDFAuto.DatasetLog();
try
{
// Attempt to fill the temporary dataset.
objDataSetTemp.LogTable.AddLogTableRow( DateTime.Now, 0, "User", info);
}
catch (System.Exception eFillDataSet)
{
// Add your error handling code here.
throw eFillDataSet;
}
try
{
grdLogTable.DataSource = null;
// Empty the old records from the dataset.
objDatasetLog.Clear();
// Merge the records into the main dataset.
objDatasetLog.Merge(objDataSetTemp);
grdLogTable.SetDataBinding(objDatasetLog, "LogTable");
}
catch (System.Exception eLoadMerge)
{
// Add your error handling code here.
throw eLoadMerge;
}
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home