Hi all,
I have created database using MS access and i want to access it in C++ how can i do that?
and also if this is possible on MFC too can anyone tell me how?
Thanks in advance.
Hi all,
I have created database using MS access and i want to access it in C++ how can i do that?
and also if this is possible on MFC too can anyone tell me how?
Thanks in advance.
Try a Search: Key Word(s): access, database
Moved to windows board, since it's all about the win32 API
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
For simple stuff I use ODBC.
Look at CRecordSet. Once you have a DSN you can derive a specific record set for each table in the DB.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
thanks all for your replies
I have done all using ODBC which really works fine with me
But there is a problem!
I want to search for an item
My project is so simple and the database is composed of only one table one of its columns is the name
what i wanna do is to add a feature to search for a name which is Data dictionary
thank you very much
Something like...
(Add exception and error handlers)
Code:CString SQL,UserName; CDataBase DB; //must open DB //then connect recordset CMyDBTableRecordSet Table(&DB); //get username from an edit? UserName.Format("Justin Case"); //set up SQL string to send to DB // get whole record from the MyDBTable for 'Justin Case' SQL.Format("SELECT * FROM MyDBTable WHERE UserName=%s",UserName); Table.Open(AFX_DB_USE_DEFAULT_TYPE, SQL ,CRecordset::none); if(!Table.IsBOF())//have records //use //close recordset //close db
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
Thanks novacain
thank you very much
I have some question what is UserName? is it the variable declaring the name field?
How can i open DB and connect to recordset?//must open DB
//then connect recordset
CMyDBTableRecordSet Table(&DB);
and what about Table(&DB) is Table is a predefined function?
what is the default type for the database is it the primary key?AFX_DB_USE_DEFAULT_TYPE
sorry for my newbie questions and thanks again for your great help
I'm not going to write this for you, have a go yourself.
Post code if you get stuck and I am happy to help (if I have time).
UserName is a variable with the search criteria (in this case the name to look for)
To open the database, declare a CDatabase variable and call the member function Open() or OpenEx()
Table in my example is a variable. Its type/class is that of a CRecordset derived from your DB's table. MSVC will do this for you (if you push the right buttons).
By specifing a pointer to an open DB (when constructing the Table variable ie Table(&DB) ) we conect the Table to the open DB.
AFX_DB_USE_DEFAULT_TYPE
Read CRecordset::Open() for more info.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
It's done
Thank you novacain for your great efforts