-
problem with db table
Hi, I've asked a few questions now in reference to db programing,
my newest problem in my learning curve, is referencing a db table. In my code I can open the db and reference a table just fine, but when I alter my code and add variables to store data from another table within the same database, and I can not get the results.
I know the db is open, but it simply does not reference the info in the table.
Has anyone had experience with table conflicts like this, could I have set the table up wrong, or ??? Could this be general problem? :(
-
What are you using ODBC ADO MFC ect?
Are you using a record set class derived from a specific table in the database?
Try closing the DB, opening it again with a new table name.
Post the code for the open and close. Here is a simple example of MFC + ODBC
Code:
//strings defined elsewhere
//DB_TABLE_TITLE the title/name of the table
//DB_DNS_NAME the Data source name installed in the PC, coresponding to the database
CDatabase DB;
//open the DB
DB.OpenEx(DB_DNS_NAME,CDatabase::noOdbcDialog);
//init the record set with the open DB
CRecordset Table(&DB);
//now open the specific table
Table.Open(AFX_DB_USE_DEFAULT_TYPE,DB_TABLE_TITLE);
//close the record set
if(Table.IsOpen())
Table.Close();
//and DB
if(DB.IsOpen())
DB.Close();
-
Thanks Novacain, sorry for the late response, been out of town! I will try the open and close of the db with different table name, thanks also for the code sample, you do things much more effeciently, I am new to this style of programing and appreciate the help, will post my findings.
Thanks again
-
Oh and I am using ODBC, I had alot of trouble getting my open calls to work, so I used a class created on codeproject.com, curious though, the calls and open messages that you used in the sample code, is that just using the CRecordset:: from afxdb.h?
I want to standardize my code, so I am learning proper methods finding books local to me on the subject have been few and far between.
-
>>the calls and open messages that you used in the sample code, is that just using the CRecordset
Yes.
You can derive a class specific to a/each table from a database.
-
Hey that db close and reopen worked like a charm, thanks for the insight, your life saver. I still have bruises from banging my head on my desk!
If you don't mind, I may have some questions with the CRecordset:: I really enjoy this type of programing, the real time data is great, but learning curve is substantial. Thanks again!