22 de abril de 2009

VSTO (Access) - Como verificar se duas tabelas são iguais?

public bool TablesAreEqual(string MyTableSource, string MyTableToCompare, string MyIndexField)
{

Access.Application oAccess = ((Access.Application)
(Marshal.GetActiveObject("Access.Application")));


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);
}
}




Sem comentários:

Enviar um comentário

Like