Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Deleting multiple records in a data Grid

Posted on 2000-02-15
11
Medium Priority
?
214 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 40 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

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