About CDatabase : Plz Help : Urgent
-
:zzz:Hello , I am new to MFC. I am using MS Access database . I want to get tables list using CDatabase. Is there ant SQL Query for getting table names from Access database. I used this code but I am getting errors. CDatabase db; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sFile= "c:\\mydabase.mdb"; sDsn.Format("ODBC;DRIVER={%s};DSN='MyDsnName';DBQ=%s",sDriver,sFile); db.Open(NULL,false,false,sDsn); CRecordset recset(&db); recset.Open(CRecordset::forwardOnly,sql,CRecordset::dynaset); CString s=recset.GetTableName(); //int n=recset.GetRecordCount(); MessageBox(s); ======== Here I am not getting table name Plz Give reply soon . Praveen. Praveen
-
:zzz:Hello , I am new to MFC. I am using MS Access database . I want to get tables list using CDatabase. Is there ant SQL Query for getting table names from Access database. I used this code but I am getting errors. CDatabase db; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sFile= "c:\\mydabase.mdb"; sDsn.Format("ODBC;DRIVER={%s};DSN='MyDsnName';DBQ=%s",sDriver,sFile); db.Open(NULL,false,false,sDsn); CRecordset recset(&db); recset.Open(CRecordset::forwardOnly,sql,CRecordset::dynaset); CString s=recset.GetTableName(); //int n=recset.GetRecordCount(); MessageBox(s); ======== Here I am not getting table name Plz Give reply soon . Praveen. Praveen
Does the database and the DSN exist? parims wrote: I used this code but I am getting errors. And what would those errors be? parims wrote: sDsn.Format("ODBC;DRIVER={%s};DSN='MyDsnName';DBQ=%s",sDriver,sFile); It looks like you are trying to create both a DSN and a DSN-less connection. Why? parims wrote: recset.Open(CRecordset::forwardOnly,sql,CRecordset::dynaset); What is the value of
sql
?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb