1 Attachment(s)
Access database with MFC, vc++ 6.0
Hi all,
I just join Codeguru. In the hope that It is Last option to try.
I am very new in VC++ 6.0. Before few day my head assign me task of implementing a printHeader module. Which I have to add into already implemented project in vc++ 6.0 before 6 or 7 years.
as I read MSDN,Ask question on many forum able to implement some what like adding data to access database.
My task is:
1] Older Project is a software which take a readings and generate Report according to it. (I do not have have to deal with it).
2] But at the time of print first printHeader is write on document then Reading are write on document.
3]Report is generated as per the companies to whom the required. Header contain Some entry from which some are constant and some have to change.
i)Company Name ii)Address iii)Order number iv)ModelNumber v)Tel no vi)Logo (logo of company- picture control(bitmap))
4]My task is to implement
i)Configure PrintHeader.Means if new company came then All above entries are store in access database.
ii)On other Dialogbox Only name of company shown in Listbox or Dropdown box. When user select particular company name then automatically entry with that company name retrieve and write into the document in Header at fixed location.
*Old Project does not used databased in it.
*Project in vc++ 6.0
*access database
Please Help. if some one implement it then I am very thank full to him/her.
Re: Access database with MFC, vc++ 6.0
The easiest way to access a database is using MFC CDatabase and CRecordset classe.
Re: Access database with MFC, vc++ 6.0
Thanks for reply. It will be great full if code is provided. It is very urjent
Re: Access database with MFC, vc++ 6.0
There is no any "universal" code for all the databases.
However, you could look at some articles describing zhe using of these two classes to work with MS Access database. For instance: http://www.codeproject.com/Articles/...-Access-databa
Re: Access database with MFC, vc++ 6.0
Is it possible to add access database to already created VC++ 6.0 MFC project ? I already go through that link. Thank you
Re: Access database with MFC, vc++ 6.0
Quote:
Is it possible to add access database to already created VC++ 6.0 MFC project ?
What for?
Database file may be anywhere in the PC (or eveb in the network). You must only know its full pathname
Re: Access database with MFC, vc++ 6.0
I am asking because up till what ever I search I found that we first select Single/Mutiple document then Database support n all Means we do all setting related to database and application at the time of creation only... So I don't know how to connect database with my project.
Re: Access database with MFC, vc++ 6.0
I never added Database support to my projects. I always wrote code to access databases from scratch.
You could connect database the same way as it was done in the codeproject example.
Re: Access database with MFC, vc++ 6.0
Ok,
SqlString = "SELECT * "
"FROM Companies "
"where CompanyName =companyname";
Please tell what is wrong in this query. And please correct me
Re: Access database with MFC, vc++ 6.0
In what language did you write this "query"?
If you meant the SQL then the query
Code:
SELECT * FROM Companies where CompanyName=companyname
seems to take not much sense while the
Code:
SELECT * FROM Companies where CompanyName='SomeName'
is syntactically correct
Re: Access database with MFC, vc++ 6.0
Re: Access database with MFC, vc++ 6.0
In my old project I write on document directly. For that class there is no Dialogbox. To store the data return by sql query we used Listbox control here. So please tell me how to access this data into that class to write on document for printpreview. Shoud I post that class code here.
Re: Access database with MFC, vc++ 6.0
So what is your problem:
connect to a database?
or access database data?
or just print / preview data in a listbox?
Re: Access database with MFC, vc++ 6.0
Quote:
Originally Posted by
VictorN
So what is your problem:
connect to a database?
or access database data?
or just print / preview data in a listbox?
I have one class which contain Onprint function this class don't have any dialogbox associated with it.
so where should
1]I write connection string?
2]where to I fired Select query?
This is my print function:
void CRsView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
//CString codeaux,codeinput,codepulseout,analogout,commout,diffinput,codecurrent,codemodel;
CRsDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(Vselect_product.m_print_original_report == 0) // report changed
{
if(Vselect_product.m_change_make == 1)
{
if(Vselect_product.make_no == 1) //company 1
{
pDoc->typetest = 3;
pDoc->Rish_name = "xyz PVT LTD";
// ObjConfig.DoModal();
// pDoc->Rish_name = ObjConfig.m_CompanyName;
pDoc->address1 = "address1"; //ObjConfig.m_Address1; //;
pDoc->address2 = "Tel: +91 11112,22222 Fax:2312124";// ObjConfig.m_Address2; //
pDoc->address3 = "E-mail : [email protected]"; // ObjConfig.m_Address3; //
}
else if(Vselect_product.make_no == 2) //zcompany 2
{
pDoc->typetest = 4;
pDoc->Rish_name = "pqr INSTRUMENTS";
pDoc->address1 = "Central Buildings";
pDoc->address2 = "Torquay , TQ2 7, U.K. Tel: +44 7777777";
pDoc->address3 = "Fax: +2313 Email:[email protected]";
}
}
}
}
Here I just want to replace those Hard coded value by variable which will be read from access database.
Re: Access database with MFC, vc++ 6.0
Quote:
Here I just want to replace those Hard coded value by variable which will be read from access database.
A mistake that many folks make when learning a new technology is they try to add the new technology into their project from the start. I say it's a mistake because often they don't understand the new technology and end up with a bunch of trial and error code in their app.
Given that, why don't you create a small test project that uses MFC to connect to the Access db? Then, once you figure out how to query (or write to) the database, you bring over the relevant code into the real project.
It might seem like this approach would take longer, but in reality it usually takes less time because you can separate the learning of the technology from the rest of your app easier and are able to bring over only the code you need.