DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Updating values in a datagrid

  1. #1
    Per Guest

    Updating values in a datagrid


    Hi
    I have a dataGrid and I would like to change the datagrid.datamember properity
    at runtime (show data from another table in the dataGrid). I hae now tried
    for 2 days without any lock.
    Can someone please help me.

    regards
    per

    My code is here

    strId = id
    Dim ad As ADODB.Connection
    Dim ar As ADODB.Recordset
    Dim fld As ADODB.Field

    Set ad = New ADODB.Connection
    'shine is my database
    Let ad.ConnectionString = "DSN=shine;UID=;PWD="
    ad.Open
    'tblOrdreNr is just some table
    strSql = "SELECT * FROM tblOrdreNr"
    Set ar = ad.Execute(strSql)
    'DataGrid1 is just the DataGrid on the form
    Set DataGrid1.DataSource = ar
    DataGrid1.DataMember = ad
    ar.Close
    ad.Close



  2. #2
    Per Guest

    Re: Updating values in a datagrid


    I found out myself :-)
    So if any of you would like to play with the DataGrid (it is very cool) and
    change it at runtime this is how you do it.

    In your DataEnvironment (the connection to the db) you can make some Commands
    (holds a table in the db)
    Now all you have to do in your code is to set the datagrids member Datamamber
    like this

    DataGridOpenOrdre.DataMember = "The name of your command"

    and then refresh it

    DataGridOpenOrdre.Refresh

    It is possible to filter the table that is hold by the command like this
    (must be done before you set the member)

    DataEnvironment1.rsCommand.Filter = "ColumnName=something"
    f.ex
    DataEnvironment1.rsCommand_tblCostumer.Filter = "costumer=HP"

    So in this way you can view part of a table in a datagrind an change the
    content at runtime.




    "Per" <vb.@127.0.0.1> wrote:
    >
    >Hi
    >I have a dataGrid and I would like to change the datagrid.datamember properity
    >at runtime (show data from another table in the dataGrid). I hae now tried
    >for 2 days without any lock.
    >Can someone please help me.
    >
    >regards
    >per
    >
    >My code is here
    >
    > strId = id
    > Dim ad As ADODB.Connection
    > Dim ar As ADODB.Recordset
    > Dim fld As ADODB.Field
    >
    > Set ad = New ADODB.Connection
    > 'shine is my database
    > Let ad.ConnectionString = "DSN=shine;UID=;PWD="
    > ad.Open
    > 'tblOrdreNr is just some table
    > strSql = "SELECT * FROM tblOrdreNr"
    > Set ar = ad.Execute(strSql)
    > 'DataGrid1 is just the DataGrid on the form
    > Set DataGrid1.DataSource = ar
    > DataGrid1.DataMember = ad
    > ar.Close
    > ad.Close
    >
    >



  3. #3
    Kshitij Guest

    Re: Updating values in a datagrid


    Hi,
    See I don't know whether this will solve your purpose or not as I am not
    using Data Environment. I am just using a recordset and setting it to Data
    grid at runtime.
    the code is :

    Dim sqlquery as String
    sqlquery = "Select * from Employee" ' SQL / Access Query

    Dim rs as Recordset ' A recordset object
    Set rs = New Recordset

    rs.CursorLocation = adUseClient ' The cursor location must be client side

    ' Open the recordset , con is the connection object
    rs.Open sqlquery, con, adOpenDynamic, adLockOptimistic

    Set dgEmpRecords.DataSource = rs ' dgEmpRecords is data grid
    dgEmpRecords.Refresh ' refresh the grid

    ' ----------------------------
    This way u can show different table data in grid at runtime

    Bye
    Kshitij
    ---------------------------------------------------
    "Per" <vb.@127.0.0.1> wrote:
    >
    >Hi
    >I have a dataGrid and I would like to change the datagrid.datamember properity
    >at runtime (show data from another table in the dataGrid). I hae now tried
    >for 2 days without any lock.
    >Can someone please help me.
    >
    >regards
    >per
    >
    >My code is here
    >
    > strId = id
    > Dim ad As ADODB.Connection
    > Dim ar As ADODB.Recordset
    > Dim fld As ADODB.Field
    >
    > Set ad = New ADODB.Connection
    > 'shine is my database
    > Let ad.ConnectionString = "DSN=shine;UID=;PWD="
    > ad.Open
    > 'tblOrdreNr is just some table
    > strSql = "SELECT * FROM tblOrdreNr"
    > Set ar = ad.Execute(strSql)
    > 'DataGrid1 is just the DataGrid on the form
    > Set DataGrid1.DataSource = ar
    > DataGrid1.DataMember = ad
    > ar.Close
    > ad.Close
    >
    >



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