Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2004, 04:57 PM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGrid Information

Dear Users,

i am trying to delete multiple records in a datagrid, at once. How is this done, please look at the code I have which deletes one record at a time....Only the record that is currently highlight, is deleted, can I highlight mulitple rows and delete all of them at the same time?

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim IRow As Integer
        Dim TRow As Integer
        Dim LRow As String
        Dim MyRow As DataRow
        Dim NTID As String
        ProgressBar1.Visible = False
        NTID = txtNTID.Text


        IRow = dgdResults.Item(dgdResults.CurrentCell)
        TRow = dgdResults.CurrentCell.RowNumber

        Dim strSQL As String = "SELECT [ID],[ItemName], [StartDate], [EndDate], [StartTime], [StopTime], [NTID] From (Requests)"
        strSQL = strSQL & " Where(([NTID]='" & NTID & "'));"
        Dim adodbConnection As New ADODB.Connection()

        adodbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\DATA\ACCESS\13FloorEquipment.mdb;"

        adodbConnection.Open()

        Dim rs As ADODB.Recordset = New ADODB.Recordset()
        Dim adoRS As Recordset = New Recordset()
        adoRS.Open(strSQL, adodbConnection, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockOptimistic, 0)
        'adoRS.Open(strSQL, adodbConnection, CursorTypeEnum.adOpenKeyset, LockTypeEnum.adLockBatchOptimistic, 0)

        If adoRS.EOF Then
            MsgBox("There are no records")
        Else
            If adoRS.RecordCount <> 0 Then
                adoRS.MoveFirst()
            End If
        End If
        Do Until adoRS.EOF
            If adoRS.Fields("ID").Value = IRow Then
                adoRS.Delete()
                GoTo Quit
            Else
                adoRS.MoveNext()
                ProgressBar1.PerformStep()
            End If
        Loop
Quit:
        MsgBox("Record is Deleted")
        adoRS.Close()
 
Old January 27th, 2004, 05:30 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I think the question has been asked before, but you never answered it: Why on earth are you using ADO and other Legacy code? Goto was banned 5 years ago ;) IMO, by coding this way, you're not using .NET to the fullest. In fact, you may even make it harder on your self than strictly necessary.

Anyway, there are a few ways to select rows in a grid and then check which rows are selected. One way is to use the Select method of the Grid. Pass it an index of the row you want to select, to select that row.

Then you can use IsSelected(rowIndex) to determine which rows are selected. Loop through all the rows in the Grid and see whether they are selected or not.

I am sure there are better ways (I am not really into the DataGrid for Windows forms), but this should at least work.

However, before you continue, I would strongly advice to "upgrade" your code to .NET. Programming classic VB and ADO in .NET is going to get you into real problems soon......

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 28th, 2004, 11:38 AM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Programmers,

One reason for me using ADO.net, is due to the fact the Database is on my company network, and is not on an SQL server..... Should that make a difference
 
Old January 28th, 2004, 11:44 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're not using ADO.NET, you're using "classic" ADO. ADO.NET is completely different from ADO. Instead of creating a Recordset, you would create a DataSet or an OleDbDataReader to access your Access database in .NET.

Take a look here: http://msdn.microsoft.com/library/de...ClassTopic.asp for more info about the DataReader and here: http://msdn.microsoft.com/library/de...ClassTopic.asp for more info about the DataSet.

I suggest you Google a bit for ADO.NET, DataSet and Tutorial. There are tons of sites out on the Web that'll teach you how to code stuff like this in "proper" .NET.

And thanks for your personal message. Would you mind posting your queries here instead of directly sending them to me? Makes things a lot easier....

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 8th, 2004, 06:57 AM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to devendra_sahumk
Default

hi i want to know how i can add four records of database
table in one row of datagrid.and each record have more than one fields in database
 
Old September 24th, 2004, 07:41 AM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar, If i select multiple row in the datagrid and then i sort the Grid,and then i wanna to delete all the selected record,But when i click on the delete button then when i loop the grid and check the IsSeleted and then delete the row then it delete only one record,
Can you suggest me this is the bug with the DataGrid.

 
Old September 24th, 2004, 10:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi sachinmahajan,

Can you please start a new thread when you have a different topic? That makes things much easier to track.

That said, I don't believe the behavior is being caused by a bug in the datagrid. Maybe it's caused by a misunderstanding of how the DataGrid works, or maybe something else is wrong.

I don't fully understand the situation (why would you sort the data after you have checked some items and are about to delete them), so can you:

a) Start a new thread for this topic (just click the New Topic link)

and

b) describe your situation in more detail. Posting the relevant parts of your code surely helps explaining the problem.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Sour Times by Portishead (Track 2 from the album: Dummy) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Information on CSS Bourke36 CSS Cascading Style Sheets 0 July 19th, 2008 03:59 AM
further information dhoward Crystal Reports 0 February 21st, 2008 03:57 PM
information about iis piyush_patel ASP.NET 1.x and 2.0 Application Design 1 September 28th, 2007 10:59 AM
Information on C# student_help C# 1 December 16th, 2005 07:34 PM
DataGrid Information KennethMungwira ADO.NET 13 November 20th, 2003 06:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.