954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Update OrderStatus in Database Table of only selected Orders in DataGridView using VB

I am developing a Windows Forms Based Application using dbo.database and Visual Basic:

I populate some Orders in DataGridView1 using LINQ 2 SQL from "tbl_Orders" where OrderStatus is "Pending". I change OrderStatus Column Type to "CheckBox" in DataGridView, Now I want that when I select some records (Orders) by checking respective checkboxes and click on "btn_UpdateStatus" Button, program pick OrderID's of only selected orders and update OrderStatus of Only selected Records (Orders) from "Pending" to "Completed" in Database Table "tbl_Orders" and DataGridView1 should be Refreshed.

I am using VB, Kindly help me with complete solution?

Code Im using is:

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Dim ID As Integer = DirectCast(DataGridViewIU68E.SelectedRows(0).Cells("EvaluationIDDataGridViewTextBoxColumn").Value, Integer)
        For i = 1 To DataGridViewIU68E.SelectedRows.Count
            Dim db As New IU68IL33EvaluationDataContext

            Dim ee = From u In db.IU68_IL33_Evaluations _
                     Where u.EvaluationID = ID _
                     Select u
            ee.EmailStatus = "Done"
            db.SubmitChanges()
        Next
    End Sub
anwar.mustafa
Newbie Poster
2 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

I may be wrong, but SelectedRows won't do it for you. SelectedRows is used for rows selected (ie clicked on or multi-selected with Shift or Control pressed while clicking) and not for rows that have been "selected" with a checkbox.

I believe you need to change SelectedRows to Rows and check the value of the checkbox. If the checkbox is checked then do your thing, if not move to the next record.

adam_k
Practically a Posting Shark
803 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: