Link to home
Start Free TrialLog in
Avatar of kukiya
kukiya

asked on

Deleting multiple records in a data Grid

Hi,
I'm trying to delete multipule records from a Data Grid that is connected to the data base throgh adodc.
There is no problem in deleting single record, but when it comes to multiple,
2 problems occur:
There is no ability to select multiple records with the mouse (only with Ctrl)
and when I do select the records with Ctrl, and then delete them,
I get the note: "Cannot delete multiple rows".

please tell me how to solve the problems, and how to delete multiple records.
Thank's alot!!!!!!
Avatar of kukiya
kukiya

ASKER

Adjusted points to 20
Write your own DELETE routine:
Disable the possibility to delete for the users and capture the DEL-key (or so).
Then fire a SQL statement which delete all the selected records!

"DELETE MyTable FROM MyTable WHERE condition = ?"


Avatar of kukiya

ASKER

My code for delete a record is through the BeforeDelete events:

Private Sub dgdEvents_BeforeDelete(Cancel As Integer)
  Dim Response As String
  Cancel = True
  Response = MsgBox("Are you sure you  
  want to delete current event?",  
  vbYesNo + vbExclamation, "Attention!")
     
  If Response = vbYes Then
     Cancel = False  'cancel the delete
  End If

End Sub

I still don't undersatnd how to select
multiple records via the mouse
and the code to delete them.....
You cannot select multiple line with the mouse, without using the keyboard!
What do u mean by 'and the code to delete them.....' ?
Avatar of kukiya

ASKER

I mean if you please can show me the code to delete the multiple records....
what can indicate the multiple selection???

Thank's
Hai kukiya , the selbookmarks gives you
the record numbers of the selected rows
from the datagrid.
Through normal iteration method we
can delete the selected records.
The code given below will do that.
reply to me

Private Sub Command1_Click()
Dim i As Integer ' Counter
Dim intCount As Integer
intCount = DataGrid1.SelBookmarks.Count - 1
ReDim arrselbk(intCount) ' Declare array to hold bookmarks.
ReDim sel(intCount)
For i = 0 To intCount
   arrselbk(i) = DataGrid1.SelBookmarks(i)
Next i
DataGrid1.Col = 0
For i = 0 To intCount
  Adodc1.Recordset.Delete
  DataGrid1.Row = arrselbk(i) - 1
Next
DataGrid1.Refresh
End Sub
Avatar of kukiya

ASKER

Thank you very much for answering me.

Your code seems to be very helpful.
only the problem is that the deletion occurs only in the the Data Grid, but not in the data base itself.
what can I do?????
Thank's lot!
What bhaspup's code did was delete the records from the recordset. However, the recordset has not updated the database file. All you need to do is a batch update after you have deleted the records: Adodc1.Recordset.UpdateBatch

After that the records should be deleted in the database itself.

--ggilman

See kukiya,
i attached the Data Grid to the ADODC
control.
so i got records deleted from the
database itself.
if not do this.

Have a adodc control and attach to the
database.
Then attach the adodc control to the
Data Grid and run.
Surely, it will run.
No need to give adodc1.recordset.updatebatch as ggilman
suggested because it will automatically
get updated.
ASKER CERTIFIED SOLUTION
Avatar of Bhaskar Ganapathe
Bhaskar Ganapathe
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kukiya

ASKER

Hi there,
The only way to delete the record from the database was with using the code:
Adodc1.Recordset.UpdateBatch

It really worked. This was very helpful!!!!

Thank you very much, both!!!