0

I want to update the AResult with click approve or reject button.

In my aspx page, here my code,

<asp:ButtonField ButtonType="Button" CommandName="Approve" Text="Approve" runat="server" />
<asp:ButtonField ButtonType="Button" CommandName="Reject" Text="Reject" runat="server" />

My aspx.vb code,

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles GridView1.RowCommand

    Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)


    con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
    con.Open()




    If e.CommandName.CompareTo("Approve") = 0 OrElse _
       e.CommandName.CompareTo("Reject") = 0 Then
        ' The Approve or Reject Button has been clicked
        ' Determine the ID of the appointment whose result was adjusted

        Dim AID As Integer = Convert.ToInt32(_GridView1.DataKeys(Convert.ToInt32(e.CommandArgument)).Value)


        Dim cmd As New SqlCommand

        cmd.Connection = con
        If e.CommandName.CompareTo("Approve") = 0 Then
            cmd = New SqlCommand("UPDATE [Appointment] SET AResulT  = N'Approve'", con)


        ElseIf e.CommandName.CompareTo("Reject") = 0 Then
            cmd = New SqlCommand("UPDATE [Appointment] SET AResult = N'Reject'", con)


        End If

        cmd.ExecuteNonQuery()

        Response.Redirect("Waiting List")

        con.Close()


    End If
End Sub

When i click on approve button, it will update my whole appointment's result with approve. Can someone teach me how to detect the row when i click the button?

Kiran Hegde
  • 3,651
  • 1
  • 16
  • 14
  • Maybe this can help you: http://stackoverflow.com/questions/2818203/get-datakey-values-in-gridview-rowcommand/6672463#6672463 – Michiel Jul 04 '14 at 09:09

1 Answers1

1

In your update statement you are not updating only one row, you are updating the whole table

  cmd = New SqlCommand("UPDATE [Appointment] SET AResulT  = N'Approve'", con)

You need to change this query to

  cmd = New SqlCommand("UPDATE [Appointment] SET AResulT  = N'Approve' WHERE [KeyColumnName]=" & AID, con)
Kiran Hegde
  • 3,651
  • 1
  • 16
  • 14