|
|
Simple 7 Steps
1)First of all import msado15.dll into your workspace
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
2)Initialize COM libraries using
CoInitialize(NULL);
3) Create connection & record set pointers
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
4) Open data base
#define STR_DATABASE L"DRIVER={sql server};SERVER=serverName;Database=datbaseName;" L"UID=sa; PWD=sa;"
HRESULT hr = S_OK;
hr = pConn->Open(STR_DATABASE, L"", L"", adOpenUnspecified);
if(FAILED(hr))
{
AfxMessageBox ("Error instantiating Connection object\n");
}
5)Execute Query and read values
try
{
CString strSQL("Select * From MyTable");
pRst->Open( _variant_t(strSQL),_variant_t((IDispatch *) pConn, true),adOpenDynamic, adLockReadOnly,adCmdText);
if(!pRst->EndOfFile){
CString strValue = (char*)(_bstr_t)pRst->Fields->Item["FieldName"]- >Value;
int nValue = (long)pRst->Fields->Item["FieldName"]->Value;
}
catch(_com_error &ce)
{
AfxMessageBox(ce.ErrorInfo);
OR
AfxMessageBox(ce.Description());
}
6)Close connection and record set pointers
if(pRst->State == adStateOpen)
pRst->Close();
if(pConn->State == adStateOpen)
pConn->Close();
7)UnInitialized COM library
::CoUninitialize();
|
|
|
|
|
Can i go like this as well
=========================================================================================
try
{
CDaoDatabase* pCDaoDb = NULL;
CDaoRecordset* pPointsSet = NULL;
pCDaoDb = new CDaoDatabase();
pCDaoDb->Open("C:\\temp\\sample2.mdb", FALSE, FALSE, "");
pPointsSet = new CDaoRecordset(pCDaoDb);
if (!pPointsSet->IsOpen())
{
pPointsSet->Open(dbOpenTable, "STUDENT", 0);
}
COleVariant oleVariant;
oleVariant = pPointsSet->GetFieldValue("STUDENTID");
long lTemp = oleVariant.lVal;
oleVariant = pPointsSet->GetFieldValue("Address");
CString strTemp = oleVariant.pcVal;
CString strTemp2 = strTemp.AllocSysString();
int nCount = pPointsSet->GetRecordCount();
//pPointsSet->
}
catch(CDaoException* e)
{
//int nError = e->ReportError();
CString error = e->m_pErrorInfo->m_strDescription;
MessageBox( NULL, error, "ERROR", MB_OK );
}
=========================================================================================
|
|
|
|
|
|
Hi!
I've used the following code to load an Object(A 3D Model).
m_Obj = new Object("Car");
m_Obj->LoadFile("demoMap/StaticMeshes/Pajero.IVE", false);
During Debugging, if I hover over m_Obj and view it as a XML file, it shows me:
"A name contained an invalid character. Error processing resource 'file:///C:/Documents and Settings/RATHAKRISHNAN/Local Set...
<bad ptr="">"
I've to use this variable to apply some material to the 3D Object. There it shows exception. How to overcome this Bad Ptr situation and resolve this exception?
|
|
|
|
|
debug the the LoadFile.
|
|
|
|
|
No. I got an exception while running the project. So I planned to inspect each variable by Debugging. While hover over this m_Obj variable, it shows Bad Ptr.
|
|
|
|
|
What line causes the exception?
m_Obj is an invalid pointer until the "new" succeeds.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I am trying to provide the language support (chinese) to one of my sample application. I have translated the strings with the chinese equivalent strings. It is working fine. When I run the application, I am able to see my sample application GUI with the Chinese strings.
But one thing I would like to know is when I compile my chinese language dll, I am getting the warnings MySampleAppChinese.rc : Could not find the file.
Why are these warnings generated? What is the reason for this?
Thanks in advance.
Taruni
|
|
|
|
|
Hi,
How can initialize array of int with NULL after its declartion.
int a[5]={NULL};//Right?
int a[5];then later how can I do the same above
|
|
|
|
|
1. Declare and init
int array[5] = {0};
2. ReInit
(a) for (i=0; i<5; i++) array[i] = 0;
(b) memset(array, 0, 5*sizeof(int));
(c) ZeroMemory(array, 5*sizeof(int));
3. Dynamic declare and init
(a)int *array;
array = new int[5];
ZeroMemory(array, 5*sizeof(int));
(b)int *array;
array = (int*) calloc(5*sizeof(int));
modified on Monday, September 22, 2008 1:57 AM
|
|
|
|
|
hi...How to a webserver in VC++ ...
|
|
|
|
|
|
You have to know programming with socket
|
|
|
|
|
Hello guys,
I wanted to convert an HDC to a CBitmap object but I don't know how to.
How can I possibly manipulate HDC and probably create a CBitmap from it.
Hope you can help me with this one.
It will be a big help.
Thanks.
|
|
|
|
|
Can you more explain HDC is a handle to device context and HBITMPA is a handle to a bitmap,for make a bitmap you can use of CreateCompatibaleBitmap.
|
|
|
|
|
Here's some code that will retrieve the currently selected bitmap from a HDC.
It should be noted that GetCurrentObject will only return a valid BITMAP if the supplpied HDC is a memory DC.
If I tried to do dcBmp = (HBITMAP)GetCurrentObject(screenDC, OBJ_BITMAP), I'd get garbage results.
If the DC you're trying to copy is not a memory DC, the alternative you have is to determine the position on screen of the image, then do a BitBlt from the screenDC to a memoryDC that has already got a HBITMAP selected onto it.
Note that having a look into the BitBlt, SelectObject, & CreateCompatibleBitmap may be necessary.
HDC screenDC, memDC;
char buffer[200];
BITMAP bmInfo;
HBITMAP dcBmp;
screenDC = GetWindowDC(hwnd);
memDC = CreateCompatibleDC(screenDC);
HBITMAP myBmp = CreateCompatibleBitmap(memDC, 100, 100);
SelectObject(memDC, myBmp);
dcBmp = (HBITMAP)GetCurrentObject(memDC, OBJ_BITMAP);
if (dcBmp)
{
GetObject(dcBmp, sizeof(bmInfo), &bmInfo);
sprintf(buffer, "Bitmap is: %d x %d pixels.", bmInfo.bmWidth, bmInfo.bmHeight);
MessageBox(hwnd, buffer, "Title", MB_OK);
}
else
MessageBox(hwnd, "Error", "Title", MB_ICONEXCLAMATION);
|
|
|
|
|
i'm looking for subj sources. some plain realization but in plain C++, without classes.
i saw all realizations placed here.. they all MFC ((
Please, help with sources if You have! )
//wbr
|
|
|
|
|
|
thx for reply. i created own one "component" yesterday.
there was a lot of routine coding, thats why i was looking for some example code.
wbr
|
|
|
|
|
I am using Visual Studios 2005 version v8.0 (.NET framework v2.0)
Hi Getting at error about _TEMPLATE_MEMBER
typedef typename allocator<T>::_TEMPLATE_MEMBER rebind<T>::other _Alloc;
I think it's something to do with _TEMPLATE_MEMBER and it only being know in ealier versions of visual sudios
Anybody know anything about it???????????????
|
|
|
|
|
Hello,
Is there a simple statement to hide the mouse pointer?
thanks
Simon
|
|
|
|
|
simon alec smith wrote: Is there a simple statement to hide the mouse pointer?
::ShowCursor(FALSE);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hi
How chanhe frame color style using CWnd::CreateEx ?
Thanks
|
|
|
|