[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Deleting multiple records in a data Grid

Posted on 2000-02-15
11
Medium Priority
?
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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

656 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