我有以下 c# 代码来过滤当前数据,同时连接到多个 MS 访问数据库表。这工作正常,但由于 Dataset ds 太大,循环需要永远返回检查调用另一个 mdb 数据库表的每一行。有没有办法优化它以删除基于列过滤器的行。
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;
}