And the other way:
public void ImportResFromAccess2Excel(xl.Range Dest)
{
object oo = Type.Missing;
//int recCount = 0;
MakeADOConnection();
ADODB.Recordset rs = new ADODB.Recordset();
rs.Open(“qryFinalReportView”, mADOConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly, (int)ADODB.CommandTypeEnum.adCmdStoredProc);
Dest.CopyFromRecordset(rs, oo, oo);
rs.MoveLast();
mDataRowCount = rs.RecordCount;
mDataColcount = rs.Fields.Count;
rs.Close();
CloseADOConnection();
}
Via the gift of an ado recordset.
the conn string for that is
mADOConn.Open(“Provider=Microsoft.Jet.OLEDB.4.0;” + “Data Source=” + msDBPath + “;”, “”, “”, 0);
Thats against an mdb.
btw I made the mistake of copying that directly from the VS IDE – turns out thats almost as bad as Word for scabby random html. I repasted it through my current fave text editor (Notepad++)
Cheers
simon
Wednesday, 22nd September, 2010 at 3:13 pm |
Simon
Your conn string works for versions prior to 2007
For those with Office 2007, according to Alexander & Clark’s book on Excel & Access Integration I think it should be Provider=Microsoft.ACE.OLEDB.12.0
Mike
Thursday, 23rd September, 2010 at 8:23 am |
Mike
you can still use Jet against 2007 .mdb files
if you are using .accb etc then yes you need something like
.Open(“Provider=Microsoft.ACE.OLEDB.12.0;” +
“Data Source=” + msDBPath + “;Persist Security Info=False;”, “”, “”, 0);
I have no idea if there are any significant differences between them – I have been using both with no obvious diffs.