Click here to Skip to main content
15,899,026 members
Home / Discussions / Database
   

Database

 
Generalusing msado15 with windows 95 Pin
umarcool22-Sep-03 0:28
umarcool22-Sep-03 0:28 
GeneralRe: using msado15 with windows 95 Pin
Steve S22-Sep-03 2:12
Steve S22-Sep-03 2:12 
GeneralRe: Works but queries Pin
umarcool22-Sep-03 20:44
umarcool22-Sep-03 20:44 
GeneralWorks but queries Pin
umarcool22-Sep-03 20:52
umarcool22-Sep-03 20:52 
GeneralRe: Works but queries Pin
Steve S24-Sep-03 4:42
Steve S24-Sep-03 4:42 
Generalusing msado15 without absolute path. Pin
umarcool22-Sep-03 0:25
umarcool22-Sep-03 0:25 
GeneralDataBindings Pin
bordonhos21-Sep-03 22:45
bordonhos21-Sep-03 22:45 
Generaldisplay data Pin
ranjjj20-Sep-03 23:22
ranjjj20-Sep-03 23:22 
the following is the ocde to accessa ms database using ADO..
the code connects it to the databse..but
how to display the output..
kindly help me in this regard..



#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>

#include "STDAFX.H"
//#include "AFX.H"
#import "c:\program files\common files\system\ado\msado15.dll" rename("EOF", "EOFile")

struct StartOLEProcess
{
StartOLEProcess()
{
::CoInitialize(NULL);
}
~StartOLEProcess()
{
::CoUninitialize();
}
} _start_StartOLEProcess;

void main(void)
{
ADODB::_ConnectionPtr m_pConnection = NULL;
ADODB::_RecordsetPtr pRecordset = NULL;
//ADODB::FieldPtr pAuthor;
//_variant_t vAuthor;
//char sAuthor[40];
//HRESULT hr = S_OK;
VARIANT *vRecordsAffected = NULL;
char ConStr[500];


//VARIANT *vRecordsAffected = NULL;
//int ctr;
/*
printf("\nEnter Database Path and File name: ");
fgets(File, 250, stdin);
for (ctr = 0; (unsigned int)ctr < strlen(File); ctr++)
{
if (File[ctr] == '\n')
{
File[ctr] = '\0';
break;
}
}
ConStr[0] = '\0';
strcat(ConStr, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=");
strcat(ConStr, File);

hr = con.CreateInstance(__uuidof(ADODB::Connection));
printf("\nCreateInstance result= %d uuidof= %d\n", hr, __uuidof(ADODB::Connection));
printf("\nConnection object created.");

con->Open(ConStr, "", "", 0);
// Create a Connection object and open it with mcb.krz, an access database


_ConnectionPtr m_pConnection; */

BOOL m_bIsConnectionOpen;

// Create an instance of _Connection
HRESULT hr ;
hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection));

cout << "Connection object created." ;
if (SUCCEEDED(hr))
{
//Open a connection where database is access database : "d:\mcb.krz"

//
/*
hr = m_pConnection->Open( _bstr_t(L"Provider=Microsoft.Jet.OLEDB.3.51);
Data Source= "c:\\emailparsing\\email_details.mdb;"), _bstr_t(L""), _bstr_t(L""),adModeUnknown);*/
ConStr[0] = '\0';
strcat(ConStr, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=");
strcat(ConStr, "c:\\emailparsing\\email_details.mdb" );

m_pConnection->Open(ConStr, "", "", 0);


//If database opened successfully then set IsConnectionOpen to TRUE

if (SUCCEEDED(hr))
{
m_bIsConnectionOpen = TRUE;
}

}

//_RecordsetPtr pRecordset;
// Here I take data from a table called KRUSE1 which has two fields a0, and a1 of TEXT type
_bstr_t bstrQuery("SELECT * FROM Emaildetails");
_variant_t vRecsAffected(0L);

try
{


ConStr[0] = '\0';
strcat(ConStr, "SELECT * FROM ");
strcat(ConStr,"Emaildetails");
pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1);


//pRecordset = m_pConnection->Execute(bstrQuery, &vRecsAffected,adOptionUnspecified);

if (!pRecordset->GetEOFile())
{
cout <<"maari" ;
int i = 0;
_variant_t vFirstName;
_variant_t vLastName;

while (!pRecordset->GetEOFile())
{
vFirstName = pRecordset->GetCollect(L"email_address") ;
cout << "success" << endl;
vLastName = pRecordset->GetCollect(L"type") ;
// now you got vFirstName and vLastName values and do whatever u want.

i++;
pRecordset->MoveNext();
}
}
pRecordset->Close();
}
catch(...)
{

}

}

the connection is been made..and i think this program is able to access the mdb file also..but how to display the data ..
what is the variable to be used to get the data and display it in the output exe file??


ranjani
GeneralMultiple SQL Query Pin
MKlucher20-Sep-03 10:21
MKlucher20-Sep-03 10:21 
GeneralRe: Multiple SQL Query Pin
Ian Darling20-Sep-03 11:44
Ian Darling20-Sep-03 11:44 
GeneralRe: Multiple SQL Query Pin
MKlucher20-Sep-03 19:40
MKlucher20-Sep-03 19:40 
Generalconnection problem, error message Pin
Giovanni Bejarasco19-Sep-03 6:11
Giovanni Bejarasco19-Sep-03 6:11 
GeneralRe: connection problem, error message Pin
Mike Dimmick20-Sep-03 12:34
Mike Dimmick20-Sep-03 12:34 
GeneralRe: connection problem, error message Pin
Giovanni Bejarasco23-Sep-03 18:15
Giovanni Bejarasco23-Sep-03 18:15 
GeneralWinforms - Connecting to SQL database on another intranet PC Pin
sunny12318-Sep-03 21:53
sunny12318-Sep-03 21:53 
GeneralRe: Winforms - Connecting to SQL database on another intranet PC Pin
Arjan Einbu18-Sep-03 22:30
Arjan Einbu18-Sep-03 22:30 
GeneralRe: Winforms - Connecting to SQL database on another intranet PC Pin
sunny12319-Sep-03 2:33
sunny12319-Sep-03 2:33 
GeneralRe: Winforms - Connecting to SQL database on another intranet PC Pin
Rob Graham20-Sep-03 18:07
Rob Graham20-Sep-03 18:07 
GeneralRe: Winforms - Connecting to SQL database on another intranet PC Pin
sunny12320-Sep-03 20:13
sunny12320-Sep-03 20:13 
GeneralRe: Winforms - Connecting to SQL database on another intranet PC Pin
Braulio Dez22-Sep-03 5:24
Braulio Dez22-Sep-03 5:24 
GeneralPlease help: Converting from SQL server 2000 to sql 7.0 Pin
Hoornet9318-Sep-03 21:13
Hoornet9318-Sep-03 21:13 
GeneralRe: Please help: Converting from SQL server 2000 to sql 7.0 Pin
Steve S18-Sep-03 22:13
Steve S18-Sep-03 22:13 
GeneralRe: Please help: Converting from SQL server 2000 to sql 7.0 Pin
Hoornet9318-Sep-03 22:37
Hoornet9318-Sep-03 22:37 
GeneralRe: Please help: Converting from SQL server 2000 to sql 7.0 Pin
Steve S19-Sep-03 1:27
Steve S19-Sep-03 1:27 
GeneralRe: Please help: Converting from SQL server 2000 to sql 7.0 Pin
Arjan Einbu18-Sep-03 22:32
Arjan Einbu18-Sep-03 22:32 

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.