Solved

Deleting multiple records in a data Grid

Posted on 2000-02-15
11
185 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now