Click here to Skip to main content
15,896,269 members
Home / Discussions / Database
   

Database

 
GeneralRe: how can i repair and compact the access2000 database using ado in vc? Pin
whelk1-Dec-02 16:10
whelk1-Dec-02 16:10 
GeneralRe: how can i repair and compact the access2000 database using ado in vc? Pin
whelk2-Dec-02 14:04
whelk2-Dec-02 14:04 
GeneralRe: how can i repair and compact the access2000 database using ado in vc? Pin
John Wong2-Dec-02 21:34
John Wong2-Dec-02 21:34 
GeneralRe: how can i repair and compact the access2000 database using ado in vc? Pin
whelk2-Dec-02 22:38
whelk2-Dec-02 22:38 
GeneralRe: how can i repair and compact the access2000 database using ado in vc? Pin
John Wong3-Dec-02 22:09
John Wong3-Dec-02 22:09 
GeneralRe: Milli second resolution in DateTime Pin
Rob Graham23-Nov-02 6:12
Rob Graham23-Nov-02 6:12 
GeneralRe: Milli second resolution in DateTime Pin
Majid Shahabfar26-Nov-02 0:34
Majid Shahabfar26-Nov-02 0:34 
QuestionRecordCount Property return me -1? Pin
anju22-Nov-02 2:07
anju22-Nov-02 2:07 
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
Nick Parker22-Nov-02 2:25
protectorNick Parker22-Nov-02 2:25 
GeneralRe: RecordCount Property return me -1? Pin
anju22-Nov-02 20:46
anju22-Nov-02 20:46 
GeneralTrying to close Access DB while app running... Pin
LukeV21-Nov-02 9:11
LukeV21-Nov-02 9:11 
GeneralRe: Trying to close Access DB while app running... Pin
Rob Graham21-Nov-02 10:14
Rob Graham21-Nov-02 10:14 
GeneralRe: Trying to close Access DB while app running... Pin
LukeV22-Nov-02 3:10
LukeV22-Nov-02 3:10 
GeneralRe: Trying to close Access DB while app running... Pin
Rob Graham22-Nov-02 8:17
Rob Graham22-Nov-02 8:17 
GeneralOpinon: Direct remote access to SQL Server Pin
clintsinger21-Nov-02 6:17
clintsinger21-Nov-02 6:17 
GeneralRe: Opinon: Direct remote access to SQL Server Pin
Rob Graham21-Nov-02 8:04
Rob Graham21-Nov-02 8:04 
GeneralSQL Server OLEDB Provider and Narrow Characters Pin
Jörgen Sigvardsson20-Nov-02 22:57
Jörgen Sigvardsson20-Nov-02 22:57 
GeneralSQL Server Syntax for a CROSSTAB QUERY from MSAccess Pin
acosmin19-Nov-02 22:42
acosmin19-Nov-02 22:42 
GeneralRe: SQL Server Syntax for a CROSSTAB QUERY from MSAccess Pin
Nick Parker20-Nov-02 8:30
protectorNick Parker20-Nov-02 8:30 
GeneralSQL Server Syntax for a CROSSTAB QUERY in MSAccess Pin
acosmin19-Nov-02 22:39
acosmin19-Nov-02 22:39 
GeneralUser / system objects Pin
leppie19-Nov-02 12:22
leppie19-Nov-02 12:22 
QuestionCreate table and choosing a datetime format ? Pin
Bart-Man19-Nov-02 9:05
Bart-Man19-Nov-02 9:05 
AnswerSolution to my problem Pin
Bart-Man19-Nov-02 10:34
Bart-Man19-Nov-02 10:34 
GeneralMove data from SQL Srever to Access Pin
Ravish18-Nov-02 23:28
Ravish18-Nov-02 23:28 
GeneralRe: Move data from SQL Srever to Access Pin
Michael P Butler18-Nov-02 23:38
Michael P Butler18-Nov-02 23:38 

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.