|
Can anyone please suggest how to work on Database i.e MS-Access in VC++ MFC Dialog Based application.I know we can use other options in MFC such as single document/multi document option and gain database support.But when we use Dialog Based option in MFC,We have to manually select the Base class as CRecordView instead of CDialog,I know that,but how to proceed after that?So to set up database connectivity in Dialog based option of MFC.Please let me know how to go about this or please tell me the articles which provide this information.I really need this.
|
|
|
|
|
Start with the CDatabase[^] and CRecordset[^] classes.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)
|
|
|
|
|
For DAO (MS-Access) classes, you should add following line to "stdafx.h" file.
<br />
#include <afxdao.h>
Then, you might use CDaoDatabase/CDaoRecordset classes like below.
CDaoDatabase db;
db.Open(pszFileName, FALSE, FALSE, pszConnect);
CDaoRecordset rs(&db);
rs.Open(dbOpenSnapshot, pszSQL, dbReadOnly | dbForwardOnly);
rs.Close();
db.Close();
Because you can not benefit from Doc/View support in a dialog, you can not use CRecordView (or CDaoRecordView for DAO) class within this type of project. If you need a "form like behavior" in a dialog, you need to implement yourself (or find an already implemented one, if any) by setting a connection between recordset and dialog (or its controls) with or without a document class.
|
|
|
|
|
Hi,
I am not able to Insert a record in Acess Table. I am Using ODBC API.
::SqlExecute(...) it is failing to Insert Records.
Please help me out.
Also if i want to move a record to a particular position how can i acieve this. Ex Rs.Move(...) Wrapper in low level ODBC API Call.
Thanks in advance,
Uday.
|
|
|
|
|
janaswamy uday wrote: ::SqlExecute(...) it is failing to Insert Records.
Why?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
UpdateData(TRUE);
SQLHENV envHandle;
SQLHDBC ConnHandle;
SQLHSTMT StmtHandle;
SQLRETURN Ret;
SQLSMALLINT szConnStroutlen;
unsigned char szConnStrout[255];
Ret = ::SQLAllocEnv(&envHandle);
if(Ret != SQL_SUCCESS)
{
AfxMessageBox("Alloc Handle is Faile",MB_OK);
}
Ret = ::SQLAllocConnect(envHandle,&ConnHandle);
if(Ret != SQL_SUCCESS)
{
AfxMessageBox("Alloc Connect is Faile",MB_OK);
}
//Connect through the Data Base in Acess
Ret = ::SQLDriverConnect(ConnHandle,
NULL,(unsigned char *)"Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\\Uday.mdb",
SQL_NTS,szConnStrout,sizeof(szConnStrout),&szConnStroutlen,SQL_DRIVER_NOPROMPT);
if(Ret != SQL_SUCCESS)
{
AfxMessageBox("SQLDriverConnect is Faile",MB_OK);
}
Ret = ::SQLAllocStmt(ConnHandle,&StmtHandle);
if(Ret != SQL_SUCCESS)
{
AfxMessageBox("SQLAllocStmt is Faile",MB_OK);
}
CString szResultant;
szResultant.Empty();
szResultant = "INSERT INTO Emp(Name,Address)VALUES (";
szResultant += "'";
szResultant += EmpName;
szResultant += "'";
szResultant += ",";
szResultant += "'";
szResultant += EmpAddress;
szResultant += "'";
szResultant += ")";
//--------> Here it is Failing. But if i hard code the Insert Statement is working Finde. But Appending to String Failed.
Ret = ::SQLExecDirect(StmtHandle,(SQLCHAR*)"INSERT INTO Emp(Name,Address)VALUES ('vijay','Saifabad')",SQL_NTS);
if(Ret != SQL_SUCCESS)
{
AfxMessageBox("SQLExecDirect is Faile",MB_OK);
}
|
|
|
|
|
I asked "Why?" not "Show me a bunch of code."
janaswamy uday wrote: CString szResultant;
szResultant.Empty();
szResultant = "INSERT INTO Emp(Name,Address)VALUES (";
szResultant += "'";
szResultant += EmpName;
szResultant += "'";
szResultant += ",";
szResultant += "'";
szResultant += EmpAddress;
szResultant += "'";
szResultant += ")";
Why not use:
szResultant.Format("INSERT INTO Emp(Name,Address) VALUES('%s','%s')", EmpName, EmpAddress); janaswamy uday wrote: //--------> Here it is Failing.
With what value?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
The Value is -1. Not able to Parse the Query String
|
|
|
|
|
janaswamy uday wrote: Not able to Parse the Query String
That came back from SQLGetDiagRec() ?
Have you compared szResultant with the string literal to see if there are any differences?
What happens if you use CString::Format() instead?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Most likely the SQL statement is not right.
Try manually with your SQL string generated by your program and see it can insert records or not.
modified on Monday, October 12, 2009 5:25 PM
|
|
|
|
|
After reading your subsequent posts, it seems to be a string type problem. That is, ANSI/UNICODE mismatch.
Try the following;
USES_CONVERSION;
Ret = ::SQLExecDirect(StmtHandle,(SQLCHAR*)T2A((LPTSTR)(LPCTSTR)szResultant),SQL_NTS);
if(Ret != SQL_SUCCESS)
{
...
}
...
|
|
|
|
|
Dear Ozer Karaaagar,
I got it and very much thankfull to you. Let Me know one more API where it will move the Record to Specific Position. Let me know the solution to Move a Record to MoveFirst,MoveNext,MovePrevious and MoveLast. Which API must be used.
If i Have to Use ::SQLSetPos(...) API. Please give me the Steps to move to Absolute Position. Please give me the solution. It is Urgent.
Thanks & Regards,
Uday.
|
|
|
|
|
I've seen AfxMessageBox() and UpdateData() functions in your code snippet, it's a MFC project as far as I understand.
So, Why won't you use CRecordset class of MFC? It provides ODBC data access and it has got all you need (Move*() functions and a limited SetAbsolutePosition()). This will simplify your job pretty much.
Anyway, for question about Move functions;
::SQLExtendedFetch() can be used with 2nd argument should be one of the SQL_FETCH_* constants (i.e. SQL_FETCH_NEXT, SQL_FETCH_PRIOR etc.)
However, you shouldn't expect to get accurate (absolute) sequential positioning in multiuser, dynamic SQL database environments. Bookmarks can also be used for that purpose.
|
|
|
|
|
Thank u very much for ur good and valuble solution.
i am very much thank full to you.
uday.
|
|
|
|
|
Not at all! 
|
|
|
|
|
Dear Experts,
i am using following code to get account expire value.But the output only shows 100 nano seconds from jan 1 1960.
so how to
1.convert the nano seconds into seconds
2.convert the seconds into date
using visual c++
CComVariant svar;
hr =x->Get(CComBSTR("accountExpire"), &svar);
if(FAILED(hr))
{
return hr;
}
// Get the IADsLargeInteger interface.
CComPtr<iadslargeinteger> spli;
long lHigh;
long lLow;
__int64 i64;
// Get the IADsLargeInteger interface.
hr = svar.pdispVal->QueryInterface(IID_IADsLargeInteger,(LPVOID*)&spli);
if(FAILED(hr))
{
return hr;
}
// Get the high and low parts of the value.
hr = spli->get_HighPart(&lHigh);
hr = spli->get_LowPart(&lLow);
// Convert the high and low parts to an __i64.
//__int64 i64;
i64 = (ULONG)lHigh;
i64 = (i64<< 32);
i64 = i64 + (ULONG)lLow;
wprintf(L"HighPart = %u, LowPart = %u, Combined = %I64d\n",lHigh, lLow, i64);
|
|
|
|
|
raja 4 wrote: 1.convert the nano seconds into seconds
You're really asking this?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Hello Friends,
I am trying to create one vc++ 6.0 application.
In which i have to create two application.
First application is server.
second is client.
server is running on admin user,and sending message to client.
client is getting the text sent by the admin.
client is login in different user in same computer.
########### code use in admin application #############
DWORD dwApp = BSM_ALLDESKTOPS|BSM_APPLICATIONS;
BroadcastSystemMessage(BSF_POSTMESSAGE,&dwApp,UWM_SEND,0,(LPARAM)sSend.GetAt(i));
########################################################
Now i am trying that same thing using MailSlots,
But not succeeded Yet.
So please help me.
Any guys have any idea.
Thanks in advance.
modified on Tuesday, October 13, 2009 12:38 AM
|
|
|
|
|
Not really sure if what you need to do is possible with mailslots, but check if the the client is able to get a valid handle to the mailslot. If not, check the error code.
What are you trying to do here?
Why is it that you want to change your existing working system?
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)
|
|
|
|
|
The Application which i want to create in not completed with any method of IPC(Inter Process Communication).
So i want help for creating one vc++ application which is running in switch beetween Windows XP users, And communicate with each other.
Thanks in advance.
|
|
|
|
|
I am compiling my code on VS2008,Which was developed using VS20056.But during compilation I am getting this error.
Embedding manifest...
.\WorXTypeLib.exe.intermediate.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
|
|
|
|
|
shilpi_gupta0708 wrote: The system cannot find the file specified.
I am pretty sure that the system cannot find the file specified. You have some choices:
1.) Copy a manifest file from another project into your current project and name it WorXTypeLib.exe.intermediate.manifest
or
2.) Right click on the project and choose 'Manifest Tool' from the treeview on the left side. Update or remove the manifest from the project.
Best Wishes,
-David Delaune
|
|
|
|
|
Does this help?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi ,Thanks for the reply.But it has the mainfest file at the place , But still not able to load.
Thanks
Shilpi
|
|
|
|