Hi, I'm having problem with my rows on gridview. When i click on the approve button, only the first row of the grid will update. Does anyone know how to make it that when i click on the different button on different row different rows will update. My code is as below...
Sub CustomersGridVi ew_RowCommand(B yVal sender As Object, ByVal e As GridViewCommand EventArgs)
' If multiple buttons are used in a GridView control, use the
' CommandName property to determine which button was clicked.
Dim str As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " & Server.MapPath( "database\db1.m db")
If e.CommandName = "Approve" Then
'Str = "Update Table3 Set Status='6' Where Status =''"
'myCommand = New OleDbCommand(St r, con)
'myCommand.Exec uteNonQuery()
'Label1.Text = ("Successful ly Approve")
'con.Close()
'Dim index As Integer
Dim mySelectQuery As String = "SELECT State, FileID FROM Table3"
Dim row As GridViewRow = GridView1.Selec tedRow
Dim myUpdateQuery As String = "Update Table3 Set State='6' where FileID=" & "'" & row.Cells(1).Te xt & "'" & ""
Dim myConnection As New OleDbConnection (Str)
Dim myCommand As New OleDbCommand(my SelectQuery, myConnection)
Dim myCommand2 As New OleDbCommand(my UpdateQuery, myConnection)
Dim retvalue As Integer
myConnection.Op en()
myCommand2.Exec uteNonQuery()
Console.WriteLi ne(retvalue)
Dim myReader As OleDbDataReader
myReader = myCommand.Execu teReader()
'Always call Read before accessing data.
While myReader.Read()
Label1.Text = ("Successful ly Approve")
End While
'always call Close when done reading.
myReader.Close( )
'Close the connection when done with it.
myConnection.Cl ose()
End If
Sub CustomersGridVi ew_RowCommand(B yVal sender As Object, ByVal e As GridViewCommand EventArgs)
' If multiple buttons are used in a GridView control, use the
' CommandName property to determine which button was clicked.
Dim str As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source= " & Server.MapPath( "database\db1.m db")
If e.CommandName = "Approve" Then
'Str = "Update Table3 Set Status='6' Where Status =''"
'myCommand = New OleDbCommand(St r, con)
'myCommand.Exec uteNonQuery()
'Label1.Text = ("Successful ly Approve")
'con.Close()
'Dim index As Integer
Dim mySelectQuery As String = "SELECT State, FileID FROM Table3"
Dim row As GridViewRow = GridView1.Selec tedRow
Dim myUpdateQuery As String = "Update Table3 Set State='6' where FileID=" & "'" & row.Cells(1).Te xt & "'" & ""
Dim myConnection As New OleDbConnection (Str)
Dim myCommand As New OleDbCommand(my SelectQuery, myConnection)
Dim myCommand2 As New OleDbCommand(my UpdateQuery, myConnection)
Dim retvalue As Integer
myConnection.Op en()
myCommand2.Exec uteNonQuery()
Console.WriteLi ne(retvalue)
Dim myReader As OleDbDataReader
myReader = myCommand.Execu teReader()
'Always call Read before accessing data.
While myReader.Read()
Label1.Text = ("Successful ly Approve")
End While
'always call Close when done reading.
myReader.Close( )
'Close the connection when done with it.
myConnection.Cl ose()
End If
Comment