Deleting Row from data file from MSFlexGrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MiziaQ
    New Member
    • Nov 2007
    • 63

    Deleting Row from data file from MSFlexGrid

    Hey, I would like to delete a row of data from my data file, though using an MSFlexGrid. I can currently delete any selected row, though it only deletes a row from the Grid, and not the entry itself. Please Help
  • VBWheaties
    New Member
    • Feb 2008
    • 145

    #2
    Originally posted by MiziaQ
    Hey, I would like to delete a row of data from my data file, though using an MSFlexGrid. I can currently delete any selected row, though it only deletes a row from the Grid, and not the entry itself. Please Help
    There are several ways to do this.
    I would do it manually by sending a DELETE query to the datasource.
    Then, refreshing the recordset the grid is based on.
    But, others may suggest otherwise.

    Comment

    • MiziaQ
      New Member
      • Nov 2007
      • 63

      #3
      Originally posted by VBWheaties
      There are several ways to do this.
      I would do it manually by sending a DELETE query to the datasource.
      Then, refreshing the recordset the grid is based on.
      But, others may suggest otherwise.
      How can I do that ? Could you give a code example please.
      Thanks

      Comment

      • VBWheaties
        New Member
        • Feb 2008
        • 145

        #4
        Originally posted by MiziaQ
        How can I do that ? Could you give a code example please.
        Thanks
        Ok, but I will be making many assumptions about your data strategy.

        Assuming each record on the grid has a primary key (or something to uniquely identifiy that record),
        when the user chooses to delete THAT record, send the records primary key to this function:

        Code:
        Public Sub DeleteRecord(PrimaryKeyValue as String)
           Dim sSql As String 
           sSql = "DELETE FROM myTable WHERE PrimaryKeyField = '" & PrimaryKeyValue & "'"
           adoCon1.Execute sSql 
        End Sub
        Then, refresh grid assuming it was binded to a ADODB recordset object:

        Code:
        Public Sub RefreshGrid()
           Dim rs As Adodb.Recordset 
           Set rs = fgData.DataSource
           rs.Requery 
           Set fgData.DataSource = rs
        End Sub
        The assumptions I made were:
        1. You have a global adodb.connectio n object called adoCon1
        2. adoCon1 is established and ready to do work.
        3. Your grid is bound to an ADODB recordset object.

        Hopefully, your actual setup is not much different. But if it is, pay more attention to the concept of deleting the record using primary key and resetting your grid from the datasource.

        Comment

        Working...