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
Deleting Row from data file from MSFlexGrid
Collapse
X
-
There are several ways to do this.Originally posted by MiziaQHey, 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
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.Originally posted by VBWheatiesThere 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.
ThanksComment
-
Ok, but I will be making many assumptions about your data strategy.Originally posted by MiziaQHow can I do that ? Could you give a code example please.
Thanks
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:
Then, refresh grid assuming it was binded to a ADODB recordset object:Code:Public Sub DeleteRecord(PrimaryKeyValue as String) Dim sSql As String sSql = "DELETE FROM myTable WHERE PrimaryKeyField = '" & PrimaryKeyValue & "'" adoCon1.Execute sSql End Sub
The assumptions I made were:Code:Public Sub RefreshGrid() Dim rs As Adodb.Recordset Set rs = fgData.DataSource rs.Requery Set fgData.DataSource = rs End Sub
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
Comment