Solved

Deleting multiple records in a data Grid

Posted on 2000-02-15
11
193 Views
Last Modified: 2007-10-18
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!!!!!!
0
Comment
Question by:kukiya
  • 5
  • 3
  • 2
  • +1
11 Comments
 

Author Comment

by:kukiya
ID: 2522595
Adjusted points to 20
0
 
LVL 12

Expert Comment

by:roverm
ID: 2522662
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 = ?"


0
 

Author Comment

by:kukiya
ID: 2523034
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.....
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 12

Expert Comment

by:roverm
ID: 2523108
You cannot select multiple line with the mouse, without using the keyboard!
What do u mean by 'and the code to delete them.....' ?
0
 

Author Comment

by:kukiya
ID: 2523159
I mean if you please can show me the code to delete the multiple records....
what can indicate the multiple selection???

Thank's
0
 
LVL 5

Expert Comment

by:Bhaskar Ganapathe
ID: 2526581
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
0
 

Author Comment

by:kukiya
ID: 2526837
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!
0
 
LVL 2

Expert Comment

by:ggilman
ID: 2529649
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

0
 
LVL 5

Expert Comment

by:Bhaskar Ganapathe
ID: 2529903
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.
0
 
LVL 5

Accepted Solution

by:
Bhaskar Ganapathe earned 20 total points
ID: 2530064
Hai Kukiya, Here is the code,
the same one.
the commnet will show you where
it deletes


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
' selected record is deleted in
'the database
  Adodc1.Recordset.Delete
  DataGrid1.Row = arrselbk(i) - 1
Next
' Data Grid is refreshed
DataGrid1.Refresh
End Sub
0
 

Author Comment

by:kukiya
ID: 2530163
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!!!

 
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question