Displaying ADO recordset in a grid 
Author Message
 Displaying ADO recordset in a grid

Hi, Is there a activeX control or a MFC view class that shows an ADO
recordset in a grid ??  Is there any other way of achieving this ??

Thanks in advance.



Wed, 25 Aug 2004 04:41:53 GMT  
 Displaying ADO recordset in a grid
Hi Shailesh
You don't need any control or Class .
.
You have to set Datasource of Grid to ADO Recordset programmatically.
Hope it works...

Saurabh
Netsity Systems (P) Ltd.

Quote:
> Hi, Is there a activeX control or a MFC view class that shows an ADO
> recordset in a grid ??  Is there any other way of achieving this ??

> Thanks in advance.



Fri, 27 Aug 2004 18:43:37 GMT  
 Displaying ADO recordset in a grid
Saurabh, I did what you have said.  But I am not able to show the grid.
What I have done is created a class from the grid ocx file (which decends
from COleDispatchDriver).  I use this class to create an instance of the
grid, then I assign the datasource property to the recordset and try to
display the window of the grid using API functions.  But the grid doesn't
show up.  I am attaching the code here.  Please tell me what is wrong here.

IMSFlexGrid m_pGrd;
 m_pGrd.SetDataSource(m_pRs); // m_pRs is a recordset interface pointer
created else where
 m_pGrd.SetEnabled(true);
 HWND hwnd;
 hwnd = (HWND)malloc(sizeof(HWND));
 hwnd->unused = m_pGrd.GetHWnd();
 ::SetParent(hwnd,this->m_hWnd);
 ::ShowWindow(hwnd,SW_SHOW);
 ::UpdateWindow(hwnd);
 ::SetWindowPos(hwnd,HWND_TOP,10,10,200,200,SWP_SHOWWINDOW);
 m_pGrd.Refresh();

Thanks in advance.



Sat, 28 Aug 2004 00:17:40 GMT  
 Displaying ADO recordset in a grid
Hi Shailesh,

Please check the DataGrid and ADO sample.
Q229029 SAMPLE: AdoDataGrid.exe Demonstrates Using ADO with DataGrid
http://support.microsoft.com/support/kb/articles/q229/0/29.asp

The code can be found at:
http://www.cyf-kr.edu.pl/ftp/softlib/full.html

Hope it helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Regards,

Bill Cheng
Microsoft Support Engineer



Sat, 28 Aug 2004 09:57:45 GMT  
 Displaying ADO recordset in a grid
Hi Shailesh

You have to check your Connection string
or Open function of Recordset pointer
You haven't sent me the code for this.
Then only i am able to help you.
You have to tell me that have you made any connection with database or not.

Saurabh
Netsity Systems (P) Ltd.


Quote:
> Saurabh, I did what you have said.  But I am not able to show the grid.
> What I have done is created a class from the grid ocx file (which decends
> from COleDispatchDriver).  I use this class to create an instance of the
> grid, then I assign the datasource property to the recordset and try to
> display the window of the grid using API functions.  But the grid doesn't
> show up.  I am attaching the code here.  Please tell me what is wrong
here.

> IMSFlexGrid m_pGrd;
>  m_pGrd.SetDataSource(m_pRs); // m_pRs is a recordset interface pointer
> created else where
>  m_pGrd.SetEnabled(true);
>  HWND hwnd;
>  hwnd = (HWND)malloc(sizeof(HWND));
>  hwnd->unused = m_pGrd.GetHWnd();
>  ::SetParent(hwnd,this->m_hWnd);
>  ::ShowWindow(hwnd,SW_SHOW);
>  ::UpdateWindow(hwnd);
>  ::SetWindowPos(hwnd,HWND_TOP,10,10,200,200,SWP_SHOWWINDOW);
>  m_pGrd.Refresh();

> Thanks in advance.



Sat, 28 Aug 2004 12:17:47 GMT  
 Displaying ADO recordset in a grid
Hi Saurabh,  I have opened the recordset with correct connection string and
I have also got the data.  The code I have used is as follows :

 m_strConnection = _T("Provider=SQLOLEDB.1;Persist Security Info=True;User
ID=sa;Initial Catalog=Northwind;Data Source=.");
 m_strCmdText = _T("select * from employees");

 try
 {
  m_pRs = NULL;
  m_pRs.CreateInstance(__uuidof(Recordset));
  m_pRs->CursorLocation = adUseClient;
  m_pRs->Open((LPCTSTR)m_strCmdText, (LPCTSTR)m_strConnection, adOpenStatic,
   adLockReadOnly, adCmdUnknown);

 }
 catch (_com_error &e)
 {
  GenerateError(e.Error(), e.Description());
 }

Also I am able to display data from the rows of the recordset in a edit
control , in the click event of a button, as follows  :

 if (!m_pRs->EndOfFile)
  m_pRs->MoveNext();
 if (!m_pRs->EndOfFile)
  UpdateControls(); // Shows data from a field in the recordset in an edit
control
 else
  AfxMessageBox("End of file reached");

The problem I have is not with the recordset but the grid control.  I am not
able to show it on a parent window, represented by "this" (as this is being
done in the member function of a class) in "::SetParent" method I have used
in the code I have already shared with you.  To give you more information
"this" is a window class derived from the MFC calss "CFrameWnd".  I have a
feeling that I am not handling the window handle of the grid control
properly.  I am missing something here.

Further help is appreciated.  Thank you.


Quote:
> Hi Shailesh

> You have to check your Connection string
> or Open function of Recordset pointer
> You haven't sent me the code for this.
> Then only i am able to help you.
> You have to tell me that have you made any connection with database or
not.

> Saurabh
> Netsity Systems (P) Ltd.



> > Saurabh, I did what you have said.  But I am not able to show the grid.
> > What I have done is created a class from the grid ocx file (which
decends
> > from COleDispatchDriver).  I use this class to create an instance of the
> > grid, then I assign the datasource property to the recordset and try to
> > display the window of the grid using API functions.  But the grid
doesn't
> > show up.  I am attaching the code here.  Please tell me what is wrong
> here.

> > IMSFlexGrid m_pGrd;
> >  m_pGrd.SetDataSource(m_pRs); // m_pRs is a recordset interface pointer
> > created else where
> >  m_pGrd.SetEnabled(true);
> >  HWND hwnd;
> >  hwnd = (HWND)malloc(sizeof(HWND));
> >  hwnd->unused = m_pGrd.GetHWnd();
> >  ::SetParent(hwnd,this->m_hWnd);
> >  ::ShowWindow(hwnd,SW_SHOW);
> >  ::UpdateWindow(hwnd);
> >  ::SetWindowPos(hwnd,HWND_TOP,10,10,200,200,SWP_SHOWWINDOW);
> >  m_pGrd.Refresh();

> > Thanks in advance.



Sun, 29 Aug 2004 02:47:02 GMT  
 Displaying ADO recordset in a grid
Hi Shailesh

Sorry for replying so late
You have to just
SetDatSource() of Grid to your Recordset like
m_Grid.SetDataSource((LPUNKNOWN)GetDocument()->m_recordSet);
in your View Class
and the Code you gave me in your OnNew() Document class
and in the end u can call UpdateAllViews() in OnNew()
and OnINitialUpdate() u can call SetDataSource()

ok
I hope it may help

Saurabh
Netsity Systems (P) Ltd.


Quote:
> Hi Saurabh,  I have opened the recordset with correct connection string
and
> I have also got the data.  The code I have used is as follows :

>  m_strConnection = _T("Provider=SQLOLEDB.1;Persist Security Info=True;User
> ID=sa;Initial Catalog=Northwind;Data Source=.");
>  m_strCmdText = _T("select * from employees");

>  try
>  {
>   m_pRs = NULL;
>   m_pRs.CreateInstance(__uuidof(Recordset));
>   m_pRs->CursorLocation = adUseClient;
>   m_pRs->Open((LPCTSTR)m_strCmdText, (LPCTSTR)m_strConnection,
adOpenStatic,
>    adLockReadOnly, adCmdUnknown);

>  }
>  catch (_com_error &e)
>  {
>   GenerateError(e.Error(), e.Description());
>  }

> Also I am able to display data from the rows of the recordset in a edit
> control , in the click event of a button, as follows  :

>  if (!m_pRs->EndOfFile)
>   m_pRs->MoveNext();
>  if (!m_pRs->EndOfFile)
>   UpdateControls(); // Shows data from a field in the recordset in an edit
> control
>  else
>   AfxMessageBox("End of file reached");

> The problem I have is not with the recordset but the grid control.  I am
not
> able to show it on a parent window, represented by "this" (as this is
being
> done in the member function of a class) in "::SetParent" method I have
used
> in the code I have already shared with you.  To give you more information
> "this" is a window class derived from the MFC calss "CFrameWnd".  I have a
> feeling that I am not handling the window handle of the grid control
> properly.  I am missing something here.

> Further help is appreciated.  Thank you.



> > Hi Shailesh

> > You have to check your Connection string
> > or Open function of Recordset pointer
> > You haven't sent me the code for this.
> > Then only i am able to help you.
> > You have to tell me that have you made any connection with database or
> not.

> > Saurabh
> > Netsity Systems (P) Ltd.



> > > Saurabh, I did what you have said.  But I am not able to show the
grid.
> > > What I have done is created a class from the grid ocx file (which
> decends
> > > from COleDispatchDriver).  I use this class to create an instance of
the
> > > grid, then I assign the datasource property to the recordset and try
to
> > > display the window of the grid using API functions.  But the grid
> doesn't
> > > show up.  I am attaching the code here.  Please tell me what is wrong
> > here.

> > > IMSFlexGrid m_pGrd;
> > >  m_pGrd.SetDataSource(m_pRs); // m_pRs is a recordset interface
pointer
> > > created else where
> > >  m_pGrd.SetEnabled(true);
> > >  HWND hwnd;
> > >  hwnd = (HWND)malloc(sizeof(HWND));
> > >  hwnd->unused = m_pGrd.GetHWnd();
> > >  ::SetParent(hwnd,this->m_hWnd);
> > >  ::ShowWindow(hwnd,SW_SHOW);
> > >  ::UpdateWindow(hwnd);
> > >  ::SetWindowPos(hwnd,HWND_TOP,10,10,200,200,SWP_SHOWWINDOW);
> > >  m_pGrd.Refresh();

> > > Thanks in advance.



Fri, 03 Sep 2004 22:27:56 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Displaying ADO recordset in a grid

2. Displaying ADO recordset in a grid

3. ADO Data Grid only Displays first two Fields

4. Problem with ADO recordsets of recordsets under MTS

5. Speed of ADO Recordset vs ADO Command in VC

6. ADO.Stream and ADO.RecordSet

7. how to display data source in several pages in ado.net like i do in ado

8. MS Data Grid Control - ADO

9. Simple ADO/Data Grid Question

10. how to bind ado recoedset to a grid

11. Looking for ADO aware grid

12. Simple ADO/Data Grid Question

 

 
Powered by phpBB® Forum Software