Office Systems Developer

Joao Livio (Portugal)

VSTO (Access) Detect if tables are similar

public bool TablesAreEqual(string MyTableSource, string 
MyTableToCompare, string MyIndexField)
{
try
{
OleDbConnection cnn;
using (DataSet ds = new DataSet())
{
OleDbDataAdapter da;
string cs =
oAccess.CurrentProject.Connection.ToString();
string strSQL =
String.Format("SELECT * FROM {0} LEFT JOIN {1} ON {0}.{2} = {1}.{2}WHERE {1}.{2} Is Null"
, MyTableSource, MyTableToCompare, MyIndexField);
cnn = new OleDbConnection(cs);
da = new OleDbDataAdapter(strSQL, cnn);
da.Fill(ds);
if (ds.Tables[0].Rows.Count <= 0)
return true;
else
return false;
}
}
catch (Exception)
{
throw;
}
finally
{
Marshal.ReleaseComObject(oAccess);
}
}

Leave a Comment

(required) 

(required) 

(optional)

(required)