Connect a DataGrid through code


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Connect a DataGrid through code

  1. #1
    Philip L Guest

    Connect a DataGrid through code


    How can I connect a datagrid through code to an access DB? I already have
    set the Recordset and the connection. What else do I need?If any.

  2. #2
    Linda Jahnke Guest

    Re: Connect a DataGrid through code


    "Philip L" <aplatfl@aol.com> wrote:
    >
    >How can I connect a datagrid through code to an access DB? I already have
    >set the Recordset and the connection. What else do I need?If any.


    I am assuming you have a data grid and a datacontrol on your form and that
    you are setting the recordset and connection properties on the data control.


    You need to set the datasource property of the data grid to the datacontrol.
    The problem is that not all datagrids allow this property to be set at run
    time. The standard datagrid only allows the datasource to be set at design
    time. You can use the MSHflexgrid instead with an ADO data control. These
    two together allow you to set recordsets and datasource programatically.

  3. #3
    Michael Guest

    Re: Connect a DataGrid through code


    "Philip L" <aplatfl@aol.com> wrote:
    >
    >How can I connect a datagrid through code to an access DB? I already have
    >set the Recordset and the connection. What else do I need?If any.


    Use the (OLEDB) DataGrid Control 6.0.
    Using ADO, get your disconnected recordset and apply it to the grid.
    Set DataGrid.Datasource = rs 'rs = ADODB.Recordset (disconnected)
    DataGrid.Refresh ' May need to refresh it

    Note: It can stay connected.
    Michael


  4. #4
    Daniel De Aguiar Guest

    Re: Connect a DataGrid through code


    "Philip L" <aplatfl@aol.com> wrote:
    >
    >How can I connect a datagrid through code to an access DB? I already have
    >set the Recordset and the connection. What else do I need?If any.



    all you need to do is assign the recordset to the datagrid's datasource property,
    i.e. set datagrid1.datasource = rs

    where rs is my recordset object.

    Dan De Aguiar


  5. #5
    Philip L Guest

    Re: Connect a DataGrid through code


    "Daniel De Aguiar" <danny.deaguiar@eds.com> wrote:
    >
    >"Philip L" <aplatfl@aol.com> wrote:
    >>
    >>How can I connect a datagrid through code to an access DB? I already have
    >>set the Recordset and the connection. What else do I need?If any.

    >
    >
    >all you need to do is assign the recordset to the datagrid's datasource

    property,
    >i.e. set datagrid1.datasource = rs
    >
    >where rs is my recordset object.
    >
    >Dan De Aguiar
    >

    My datagrid does not populate. What am i missing or doing wrong ?
    This is my code:

    Private rsLoginout As ADODB.Recordset
    Private cnRESDATA As ADODB.Connection

    Set cnRESDATA = New ADODB.Connection
    cnRESDATA.ConnectionString = "Provider = " _
    & "Microsoft.Jet.OLEDB.4.0; " _
    & "Data Source = " & "G:\RESDATA_DEV.mdb"
    cnRESDATA.Open
    Set rsLoginout = New ADODB.Recordset

    strSQL = "SELECT * FROM ViewLoginout WHERE Date = # 1/2/01 # ORDER BY Userid"
    Call rsLoginout.Open(strSQL, cnRESDATA, _
    adOpenStatic, adLockPessimistic, adCmdText)

    Set dgdLoginout.DataSource = rsLoginout




  6. #6
    Nguyen Khanh Guest

    Re: Connect a DataGrid through code


    "Linda Jahnke" <LindaJahnke@msn.com> wrote:
    >
    >"Philip L" <aplatfl@aol.com> wrote:
    >>
    >>How can I connect a datagrid through code to an access DB? I already have
    >>set the Recordset and the connection. What else do I need?If any.

    >
    >I am assuming you have a data grid and a datacontrol on your form and that
    >you are setting the recordset and connection properties on the data control.
    >
    >
    >You need to set the datasource property of the data grid to the datacontrol.
    > The problem is that not all datagrids allow this property to be set at

    run
    >time. The standard datagrid only allows the datasource to be set at design
    >time. You can use the MSHflexgrid instead with an ADO data control. These
    >two together allow you to set recordsets and datasource programatically.



  7. #7
    Philip L Guest

    Re: Connect a DataGrid through code


    "Nguyen Khanh" <khanh1410@yahoo.com> wrote:
    >
    >"Linda Jahnke" <LindaJahnke@msn.com> wrote:
    >>
    >>"Philip L" <aplatfl@aol.com> wrote:
    >>>
    >>>How can I connect a datagrid through code to an access DB? I already have
    >>>set the Recordset and the connection. What else do I need?If any.

    >>
    >>I am assuming you have a data grid and a datacontrol on your form and that
    >>you are setting the recordset and connection properties on the data control.
    >>

    Thanks everyone for their responses..
    >>
    >>You need to set the datasource property of the data grid to the datacontrol.
    >> The problem is that not all datagrids allow this property to be set at

    >run
    >>time. The standard datagrid only allows the datasource to be set at design
    >>time. You can use the MSHflexgrid instead with an ADO data control. These
    >>two together allow you to set recordsets and datasource programatically.

    >



  8. #8
    Samuel Jackson Guest

    Re: Connect a DataGrid through code


    "Philip L" <aplatfl@aol.com> wrote:
    >
    >"Daniel De Aguiar" <danny.deaguiar@eds.com> wrote:
    >>
    >>"Philip L" <aplatfl@aol.com> wrote:
    >>>
    >>>How can I connect a datagrid through code to an access DB? I already have
    >>>set the Recordset and the connection. What else do I need?If any.

    >>
    >>
    >>all you need to do is assign the recordset to the datagrid's datasource

    >property,
    >>i.e. set datagrid1.datasource = rs
    >>
    >>where rs is my recordset object.
    >>
    >>Dan De Aguiar
    >>

    >My datagrid does not populate. What am i missing or doing wrong ?
    >This is my code:
    >
    >Private rsLoginout As ADODB.Recordset
    >Private cnRESDATA As ADODB.Connection
    >
    >Set cnRESDATA = New ADODB.Connection
    > cnRESDATA.ConnectionString = "Provider = " _
    > & "Microsoft.Jet.OLEDB.4.0; " _
    > & "Data Source = " & "G:\RESDATA_DEV.mdb"
    > cnRESDATA.Open
    > Set rsLoginout = New ADODB.Recordset
    >
    >strSQL = "SELECT * FROM ViewLoginout WHERE Date = # 1/2/01 # ORDER BY Userid"
    > Call rsLoginout.Open(strSQL, cnRESDATA, _
    > adOpenStatic, adLockPessimistic, adCmdText)
    >
    >Set dgdLoginout.DataSource = rsLoginout
    >
    >
    >


    Philip,

    You need to set the CursorLocation property of recordset (or connection)
    object to adUseClient. If I didn't specify this, adUseServer (default) will
    be used.

    Good Luck,

    Samuel Jackson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center