Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i display information from several tables in ADO

Status
Not open for further replies.

rwong

Programmer
Joined
Apr 16, 2002
Messages
68
Location
CR
Help!
Does anyone knows how do i extract information from more than one table when using ADO?
I know how to create several recordset objects, but i am using different queries to configure those recordsets and i want to display information from all of them, i tried to create two different derived classes from the CADORecordBinding class but it didn't work,

Is there an easy way?
How do i find the CADORecordBinding class throughout the "Class Wizard"?

Thanx & Regards

Ricardo
 
Are you talking about a SQL join accross tables or are you refering to the ADO.NET Multiple Recordset capability?

The first can be done with a simple SQL query. The latter requires ADO.NET.

For help on the SQL query syntax go to your SQL forum here at Tek-Tips.

For help with Multiple Recordsets in ADO.NET go to msdn.microsoft.com and look at the tutorials and examples for using ADO.NET.

does that help?
-pete
 
Thank you, Pete,

I am using Visual C++ 6.0, so i am not able to work with ADO.NET, i will try to be more especific:

I am using several SQL statements to build several recordsets, e.g.:

m_strConnection =
_T"DSN=Sports;UID=myuserid;PWD=mypassword;");
m_strCmdText = _T("select * from Players");

m_pPlayerSet = NULL;
m_pTeamSet = NULL;
m_piAdoRecordBinding = NULL;

::CoInitialize(NULL);
try
{
m_pPlayerSet.CreateInstance(__uuidof(Connection));
// Create the recordset object
m_pPlayerSet.CreateInstance(__uuidof(Recordset));

// Open the recordset object
m_pPlayerSet->Open((LPCTSTR)m_strCmdText, (LPCTSTR) m_strConnection, adOpenDynamic,
adLockOptimistic, adCmdUnknown);

if (FAILED(m_pPlayerSet->QueryInterface(__uuidof(IADORecordBinding), (LPVOID *)&m_piAdoRecordBinding)))
_com_issue_error(E_NOINTERFACE);
// Bind the record class to the recordset
m_piAdoRecordBinding->BindToRecordset(&m_rsRecSet);

pos = GetFirstViewPosition();
CDbAdoView* pView = (CDbAdoView*)GetNextView(pos);
if (pView)
// Sync the data set with the form
pView->RefreshBoundData();
}
catch (_com_error &e)
{
GenerateError(e.Error(), e.Description());
}

What i can't do is:
// now i change the sql string
m_strCmdText = _T("select * from Players");

try {

m_pTeamSet.CreateInstance(__uuidof(Connection));
// Create the recordset object
m_pTeamSet.CreateInstance(__uuidof(Recordset));
m_pTeamSet->Open((LPCTSTR)m_strCmdText, (LPCTSTR) m_strConnection, adOpenDynamic,
adLockOptimistic, adCmdUnknown);

if (FAILED(m_pTeamSet->QueryInterface(__uuidof(IADORecordBinding), (LPVOID *)&m_piAdoRecordBinding)))
_com_issue_error(E_NOINTERFACE);

when i try to bind this to an ADORecordBinding object, i require something else and i don't know how to create it, do you know how?


Regards

Ricardo

 
>>// now i change the sql string
The second version doesn't look very different from the first one.

I guess you'll have to do as Palbano says, join the recordsets when you retrieve them from the DB with SQL JOINS.

Greetings,
Rick
 
>> i require something else

i don't understand that "something else" could you be more specific.

The code does not compile? Post the compile error.

The code throws an Exception? Post the exception message.

-pete
 
Thank you Pete!

I finally solved the problem creating several recordset objects and several CADORecordBinding objects from diferent classes. I really don't think is the most efficient way to do it, but it works, and i find it easier than using "GetCollect" instructions, like the example posted in the FAQ section.

Is a little akward but the first time i tried to compile my derived class from CADORecordBinding it throws me a few error messagges, but i tried again and worked fine,

Regards,

Ricardo

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top