我想用单击“批准”或“拒绝”按钮更新AResult。
在我的aspx页面,这里是我的代码,
<asp:ButtonField ButtonType="Button" CommandName="Approve" Text="Approve" runat="server" />
<asp:ButtonField ButtonType="Button" CommandName="Reject" Text="Reject" runat="server" />我的aspx.vb代码,
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当我单击“批准”按钮时,它将使用“批准”更新我的整个约会结果。当我点击按钮时,有人能教我如何检测行吗?
发布于 2014-07-04 09:17:44
在update语句中,不是只更新一行,而是更新整个表。
cmd = New SqlCommand("UPDATE [Appointment] SET AResulT = N'Approve'", con)您需要将此查询更改为
cmd = New SqlCommand("UPDATE [Appointment] SET AResulT = N'Approve' WHERE [KeyColumnName]=" & AID, con)https://stackoverflow.com/questions/24570569
复制相似问题