I have the following c# code to filter at present data while connecting to multiple MS access database Tables. This works fine but as the Dataset ds is too huge for loop takes forever to return checking each row calling another mdb database table. Is there a way to optimize this to delete the rows based on the column filters.
string ABCACCESSDataSource = @"c:\websites\abc.mdb";
string XYZACCESSDataSource = @"c:\websites\xyz.mdb";
private void dataviewTable()
{
OleDbConnection Conn = DatabaseCommands.openDBConnection(ABCACCESSDataSource, this);
string query1 = select column1, column2, column3 from ABCTable where column2 = 'hello' order by column1;
Dataview dv;
OleDbDataAdapter da = new OleDbDataAdapter(query1, Conn);
DataSet ds = new System.Data.DataSet();
da.Fill(ds, "ABCTable");
foreach (DataRow dr in ds.Tables["ABCTable"].Rows)
checkValue = dr["ABCTable"].ToString();
{
resultvalue = getvalue(checkValue);
if(resultvalue == "unavailable")
{
dr.delete();
}
dv = ds.Tables["ABCTable"].DefaultView;
}
private string getvalue(string checkValuepassed)
{
OleDbConnection Conn2 = DatabaseCommands.openDBConnection(XYZACCESSDataSource, this);
string query2 = select columnX from XYZTable where columnY = 'test' AND columnZ = '" + checkValuepassed +"'" ;;
OleDbDataAdapter da2 = new OleDbDataAdapter(query2, Conn2);
ds2 = new DataSet();
da2.Fill(ds2);
resultVal = ds2.Tables[0].Rows[0][0].ToString() ;
return resultVal;
}
If you are getting a single value then putting it in Table to retrieve the values is slow.
But retrieve the values once.
Another way to look at this is not loop the ABC.
Just loop XYZ and issue delete commands to ABC.
If the record is not there it will delete nothing.
And batch up in groups of like 10-100.
There will be sweet spot.
Delete [XYX] where [ABCTable] in (..,..,..);