我的更新按钮仅更新第一个选中的行而不更新其他行
我要更新数据库,但它只对选定的第一行进行更新,而不对其他行进行更新。
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs)
For Each row As GridViewRow In GridView6.Rows
' Selects the text from the TextBox
Dim selectedcheck As CheckBox = CType(row.FindControl("chkselect"), CheckBox)
If selectedcheck.Checked = True Then
Dim id As Label = CType(row.FindControl("id"), Label)
cmd.Parameters.AddWithValue("@id", id.Text)
cmd.Parameters.AddWithValue("@compby", txtagent.Text)
cmd.Parameters.AddWithValue("@compdate", lbldate.Text)
cmd.Parameters.AddWithValue("@comments", txtcomments.Text)
cmd.CommandText = "dbo.updatetasks"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = conn
conn.Open()
cmd.BeginExecuteNonQuery()
conn.Close()
End If
Next
End Sub
UPDATE dashboardtasks
SET compby = @compby,
comments = @comments,
compdate = @compdate
WHERE id = @id;
I got the database to update, but it only does it for the first row selected not for the others.
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs)
For Each row As GridViewRow In GridView6.Rows
' Selects the text from the TextBox
Dim selectedcheck As CheckBox = CType(row.FindControl("chkselect"), CheckBox)
If selectedcheck.Checked = True Then
Dim id As Label = CType(row.FindControl("id"), Label)
cmd.Parameters.AddWithValue("@id", id.Text)
cmd.Parameters.AddWithValue("@compby", txtagent.Text)
cmd.Parameters.AddWithValue("@compdate", lbldate.Text)
cmd.Parameters.AddWithValue("@comments", txtcomments.Text)
cmd.CommandText = "dbo.updatetasks"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = conn
conn.Open()
cmd.BeginExecuteNonQuery()
conn.Close()
End If
Next
End Sub
UPDATE dashboardtasks
SET compby = @compby,
comments = @comments,
compdate = @compdate
WHERE id = @id;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望以下内容能够工作:
如果您使用了 ExecuteNonQuery 的同步变体,或者遵守了异步方法的约定(您必须调用
EndExecuteNonQuery
来发现 SQL 调用的结果。I'd expect the following to work:
You would have gotten a nice exception telling you what you'd done wrong if you'd used the synchronous variant of
ExecuteNonQuery
, or obeyed the contract for Asynchronous methods (where you have to callEndExecuteNonQuery
to discover the result of your SQL call.