-
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.
-
Re: Access database with MFC, vc++ 6.0
ON_BN_CLICKED(IDC_READ, OnRead);
BOOL CReadDBDlg::OnInitDialog()
{
}
I want to call ON_BN_CLICKED in OnInitDialog() how to do that. It will be great full if code example mention
-
Re: Access database with MFC, vc++ 6.0
Code:
BOOL CReadDBDlg::OnInitDialog()
{
...
OnRead();
}
-
Re: Access database with MFC, vc++ 6.0
Look at the CRecordset class. It does almost all of the work for you.
-
Re: Access database with MFC, vc++ 6.0
ON_BN_CLICKED(IDC_READ, OnRead)
This is my button click event I want to call it in OnInitDialog() Method
BOOL CReadDBDlg2::OnInitDialog()
How to do this?
-
Re: Access database with MFC, vc++ 6.0
Quote:
ON_BN_CLICKED(IDC_READ, OnRead)
This is my button click event I want to call it in OnInitDialog() Method
BOOL CReadDBDlg2::OnInitDialog()
How to do this?
I wonder, don't you read the answers to your previous questions? :confused:
There is the post#17:
Quote:
Originally Posted by
VictorN
Code:
BOOL CReadDBDlg::OnInitDialog()
{
...
OnRead();
}
-
Re: Access database with MFC, vc++ 6.0
I want to call BN_CLICKED it self
-
Re: Access database with MFC, vc++ 6.0
Quote:
I want to call BN_CLICKED it self
Why?
Note that BN_CLICKED is just some UINT constant, ON_BN_CLICKED(IDC_READ, OnRead) is a macro that show the compiler what function must be called in response to the IDC_READ button click.
So if don't want to call this function directly then you should simulate the button click sending the WM_COMMAND message with corresponding WPARAM and LPARAM. See https://msdn.microsoft.com/en-us/lib...or=-2147217396
-
Re: Access database with MFC, vc++ 6.0
Dear [email protected],
please, don't delete the posts that were already answered! Otherwise you will break the logic!
-
Re: Access database with MFC, vc++ 6.0
Quote:
Originally Posted by
VictorN
Dear
[email protected],
please, don't delete the posts that were already answered! Otherwise you will break the logic!
Actually I did not see answer and posted question also on second page. After I saw that that's why I delete it. Sorry for that Sir.
Please mention a code for That BN_CLICKED(...) macro. to call in initDiaog() method
-
Re: Access database with MFC, vc++ 6.0
Quote:
Please mention a code for That BN_CLICKED(...) macro. to call in initDiaog() method
See the post#17, post#23
-
Re: Access database with MFC, vc++ 6.0
Ok,
How we can close the open dialogbox through code at runtime
-
Re: Access database with MFC, vc++ 6.0
I want to display Logo on my document like other data which I retrieve from database are store into variable and then those are passes to print on document. I am storing path of related bitmap in database and it is also retrieve into variable I know following:
hbit = (HBITMAP) LoadImage(AfxGetInstanceHandle(),
// MAKEINTRESOURCE(IDB_BITMAP4),
MAKEINTRESOURCE(IDB_BITMAPNAME),
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION); SRCCOPY);
IDB_BITMAPNAME is a BITMAP which File Name Property set to the logo's path.
This is a static way to do means I already set FileName Property of BITMAP. I want to set it at runtime. please help
-
Re: Access database with MFC, vc++ 6.0
Quote:
I want to display Logo on my document like other data which I retrieve from database are store into variable and then those are passes to print on document. I am storing path of related bitmap in database and it is also retrieve into variable I know following:
hbit = (HBITMAP) LoadImage(AfxGetInstanceHandle(),
// MAKEINTRESOURCE(IDB_BITMAP4),
MAKEINTRESOURCE(IDB_BITMAPNAME),
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION); SRCCOPY);
IDB_BITMAPNAME is a BITMAP which File Name Property set to the logo's path.
This is a static way to do means I already set FileName Property of BITMAP. I want to set it at runtime. please help
Wait, did you solve the other problem with reading data from the database?
-
Re: Access database with MFC, vc++ 6.0
I tried as follows but not work,
hbit = (HBITMAP) LoadImage(NULL,
// MAKEINTRESOURCE(IDB_BITMAP4),
sLogopath,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE);
sLogoPath is CString type variable which contain C:\Users\Administrator\Desktop\cg_logoa.bmp path of bitmap
I also tried for dilectly mention path instead of variable "C:\\Users\\Administrator\\Desktop\\cg_logoa.bmp"
Also tried for this
L"C:\\Users\\Administrator\\Desktop\\cg_logoa.bmp" but it gives following error
error C2664: 'LoadImageA' : cannot convert parameter 2 from 'unsigned short [44]' to 'const char *'
-
Re: Access database with MFC, vc++ 6.0
Please reply soon. kindly I am waiting
-
Re: Access database with MFC, vc++ 6.0
Quote:
Originally Posted by
Arjay
Wait, did you solve the other problem with reading data from the database?
Yes I Completed.
-
Re: Access database with MFC, vc++ 6.0
-
Re: Access database with MFC, vc++ 6.0
I completed with this. Please help me for LoadImage bitmap question
-
Re: Access database with MFC, vc++ 6.0
Quote:
I completed with this. Please help me for LoadImage bitmap question
What does it have to do with the "Access database with MFC, vc++ 6.0" topic?
Please, start a new thread with this new question.
Besides, if you "completed" the DB access problem them mark this thread as Resoved.
-
Re: Access database with MFC, vc++ 6.0
Quote:
I tried as follows but not work,
hbit = (HBITMAP) LoadImage(NULL,
// MAKEINTRESOURCE(IDB_BITMAP4),
sLogopath,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE);
sLogoPath is CString type variable which contain C:\Users\Administrator\Desktop\cg_logoa.bmp path of bitmap
I also tried for dilectly mention path instead of variable "C:\\Users\\Administrator\\Desktop\\cg_logoa.bmp"
Also tried for this
L"C:\\Users\\Administrator\\Desktop\\cg_logoa.bmp" but it gives following error
error C2664: 'LoadImageA' : cannot convert parameter 2 from 'unsigned short [44]' to 'const char *'
Please help me for this question, If nothing wrong then please tell i am waiting.Now it is urjent