Click here to Skip to main content
15,910,603 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Excel grids? Pin
Obliterator22-Nov-02 7:21
Obliterator22-Nov-02 7:21 
Generaladd some color to propertysheet Pin
Deepti22-Nov-02 3:46
Deepti22-Nov-02 3:46 
GeneralSetForegroundWindow.... Pin
Neha22-Nov-02 2:56
Neha22-Nov-02 2:56 
GeneralRe: SetForegroundWindow.... Pin
David Viggiano22-Nov-02 3:10
David Viggiano22-Nov-02 3:10 
GeneralChecking ISDN on Win98 Pin
Tili22-Nov-02 2:56
Tili22-Nov-02 2:56 
GeneralManually creating a wave file Pin
Hamza22-Nov-02 2:41
Hamza22-Nov-02 2:41 
GeneralRe: Manually creating a wave file Pin
Maximilien22-Nov-02 3:25
Maximilien22-Nov-02 3:25 
QuestionRecordCount Property return me -1? Pin
anju22-Nov-02 2:11
anju22-Nov-02 2:11 
Hi,All

RecordCount Property giving me -1 value
Please read my code and give me where i am doing wrong;
and also please comment on my Code(if their any mistakes)
Thanks in Advance..

/////////////This is my code To Test the Function////////////////////


_RecordsetPtr pRst;
CString strTemp;
pRst.CreateInstance(__uuidof(Recordset));
pRst=GetData(1);
if(pRst!=NULL)
{
int nCount=(int)pRst->RecordCount;
strTemp.Format("%d",nCount);
AfxMessageBox(strTemp);
}
else
{
AfxMessageBox("Recordset null");
}
pRst.Close();
pRst.Release();

////////////////////////////////////

///////////////////This is my funtion which will return me Recordset object///////////
_RecordsetPtr GetData(int nType)
{
CString strType;
strType.Format("%d",nType);
try
{
//COM Library Initialization
if(FAILED(::CoInitialize(NULL)))
{
//Log error
return NULL;
}//if(FAILED(::CoInitialize(NULL))

//Open the Connection
m_hr=m_pConnection.CreateInstance(__uuidof(Connection));
if(FAILED(m_hr))
{
::CoUninitialize();
//Log error
return NULL;
}

m_strCnnString=GetConnectionString();//It will give me the Connection String
_bstr_t cnnString(m_strCnnString);
_bstr_t bstrEmpty("");

m_hr=m_pConnection->Open(cnnString,bstrEmpty,bstrEmpty,adConnectUnspecified);
if(FAILED(m_hr))
{
m_pConnection.Release();
::CoUninitialize();
//Log error
return NULL;
}

//Get the Command objet
m_hr=m_pCommand.CreateInstance(__uuidof(Command));
if(FAILED(m_hr))
{
m_pConnection->Close();
m_pConnection.Release();
::CoUninitialize();
//Log error
return NULL;
}
m_pCommand->ActiveConnection=m_pConnection;
m_pCommand->CommandText="Sp_GetData";
m_pCommand->CommandType=adCmdStoredProc;


//Append the Parameters to Command object

//Type Parameter
m_pParam=m_pCommand->CreateParameter(_bstr_t("Type"),adInteger,adParamInput,4,_variant_t(strType));
m_pCommand->Parameters->Append(m_pParam);

m_hr=m_pRecordSet.CreateInstance(__uuidof(Recordset));

if(FAILED(m_hr))
{
m_pConnection->Close();
m_pConnection.Release();
::CoUninitialize();
//Log error
return NULL;
}
//Execute the SP
m_pRecordSet->CursorType=adOpenStatic;
m_pRecordSet=m_pCommand->Execute(NULL,NULL,adCmdStoredProc);
return m_pRecordSet;

}//try block
catch(_com_error &comExcep)
{
//Handle the error
}
catch(CException * GenExcep)
{
//Handle the error
GenExcep->Delete();
}

//CleanUp the objects
if(m_pCommand!=NULL)
{
m_pCommand.Release();
}
if(m_pConnection!=NULL)
{
m_pConnection->Close();
m_pConnection.Release();
}
::CoUninitialize();
return NULL;

}


//////////////////This is my StoredProcedure /////////
CREATE PROCEDURE [dbo].[Sp_GetData]
(
@Type[int]
)

AS
Begin

SELECT
Data1,
Data2,
Data3
Data4,
Data5
FROM
tblTestData

WHERE
(Data1=@Type)

End
GO
////////////////////////////////
Rose | [Rose] Rose | [Rose] Rose | [Rose]


anju
AnswerRe: RecordCount Property return me -1? Pin
Jon Hulatt22-Nov-02 2:25
Jon Hulatt22-Nov-02 2:25 
AnswerRe: RecordCount Property return me -1? Pin
Nick Parker22-Nov-02 2:30
protectorNick Parker22-Nov-02 2:30 
GeneralVoice Conferencing over Internet - HOW Pin
Kunal Khairnar22-Nov-02 1:02
Kunal Khairnar22-Nov-02 1:02 
GeneralRe: Voice Conferencing over Internet - HOW Pin
SteveKing22-Nov-02 1:12
SteveKing22-Nov-02 1:12 
GeneralWindows Security Pin
Richard Hudson22-Nov-02 0:51
Richard Hudson22-Nov-02 0:51 
GeneralRe: Windows Security Pin
SteveKing22-Nov-02 1:07
SteveKing22-Nov-02 1:07 
GeneralRe: Windows Security Pin
Richard Hudson22-Nov-02 2:44
Richard Hudson22-Nov-02 2:44 
QuestionHow to trap event with combination of EditBox and ComboBox Pin
21-Nov-02 23:39
suss21-Nov-02 23:39 
Generalloading icon Pin
Subhashree21-Nov-02 22:43
Subhashree21-Nov-02 22:43 
GeneralRe: loading icon Pin
Jon Hulatt21-Nov-02 23:21
Jon Hulatt21-Nov-02 23:21 
GeneralRe: loading icon Pin
Renjith Ramachandran22-Nov-02 2:05
Renjith Ramachandran22-Nov-02 2:05 
GeneralMS Project2002 SDK Pin
Abubakar Siddque21-Nov-02 22:40
Abubakar Siddque21-Nov-02 22:40 
GeneralRe: MS Project2002 SDK Pin
Christian Graus21-Nov-02 22:44
protectorChristian Graus21-Nov-02 22:44 
GeneralRe: MS Project2002 SDK Pin
Michael P Butler22-Nov-02 0:35
Michael P Butler22-Nov-02 0:35 
GeneralRe: MS Project2002 SDK Pin
Christian Graus22-Nov-02 1:07
protectorChristian Graus22-Nov-02 1:07 
GeneralRe: MS Project2002 SDK Pin
carrie22-Nov-02 1:54
carrie22-Nov-02 1:54 
GeneralRe: MS Project2002 SDK Pin
Christian Graus22-Nov-02 9:25
protectorChristian Graus22-Nov-02 9:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.