问题描述
您好...我在更新数据网格时遇到问题。
我的代码中的所有内容看起来都不错,所以我不知所措。我可以
点击更新,网格将重新绑定...但不是我的
更新数据。我没有在pageload中回帖...而且它的
不是数据库权限导致我可以插入。请
帮助!这是我的代码:
Sub dgStaff_Update(ByVal sender As Object,ByVal e As
DataGridCommandEventArgs)
''获取值out of datagrid to update
Dim intID As Integer = e.Item.Cells(0).Text
Dim strGrp As String = e.Item.Cells(1) .Text
Dim nameTextBox As TextBox = e.Item.Cells
(2).FindControl(" txtDGName")
Dim posTextBox As TextBox = e.Item.Cells
(3).FindControl(" txtDGPos")
Dim numTextBox As TextBox = e.Item.Cells
(4).FindControl(" txtDGNum")
Dim strSql As String =" UPDATE tbl_parishstaff Set
person = @ person,pos = @ pos,num = @ num WHERE id = @ id"
''创建新的更新对象并添加参数
Dim updateClergyStaff As OleDb.OleDbCommand = New
OleDb.OleDbCommand(strSql,Me.OleDbConnection1)
updateClergyStaff.Parameters.Add(" @ id",intID)
updateClergyStaff.Parameters.Add(" @ grp",strGrp)
updateClergyStaff.Parameters.Add(" @ person",
nameTextBox.Text)
updateClergyStaff.Parameters.Add(" @ pos",
posTextBox.Text)
updateClergyStaff.Parameters.Add(" @ num" ;,
numTextBox.Text)
''打开数据库,更新数据,关闭
数据库。
updateClergyStaff.Connection.Open()
updateClergyStaff.ExecuteNonQuery()
Response.Write(updateClergyStaff.ExecuteNonQuery。)
updateClergyStaff.Connection。关闭()
''更新数据填充网格后更新信息
并返回正常状态
dgStaff.EditItemIndex = -1
daStaff.Fill(DsStaff1)
dgStaff.DataBind()
End Sub
Hello... Im having a problem getting a datagrid to update.
Everything in my code looks ok so Im at a loss. I can
click update and the grid will rebind... but not with my
updated data. I am not posting back in pageload... And its
not database permissions cause I can do inserts. Please
Help! here is my code:
Sub dgStaff_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
''Get values out of the datagrid to update
Dim intID As Integer = e.Item.Cells(0).Text
Dim strGrp As String = e.Item.Cells(1).Text
Dim nameTextBox As TextBox = e.Item.Cells
(2).FindControl("txtDGName")
Dim posTextBox As TextBox = e.Item.Cells
(3).FindControl("txtDGPos")
Dim numTextBox As TextBox = e.Item.Cells
(4).FindControl("txtDGNum")
Dim strSql As String = "UPDATE tbl_parishstaff Set
person=@person, pos=@pos, num=@num WHERE id=@id"
''Create new update object and add parameters
Dim updateClergyStaff As OleDb.OleDbCommand = New
OleDb.OleDbCommand(strSql, Me.OleDbConnection1)
updateClergyStaff.Parameters.Add("@id", intID)
updateClergyStaff.Parameters.Add("@grp", strGrp)
updateClergyStaff.Parameters.Add("@person",
nameTextBox.Text)
updateClergyStaff.Parameters.Add("@pos",
posTextBox.Text)
updateClergyStaff.Parameters.Add("@num",
numTextBox.Text)
''Open the database, update the data, close
database.
updateClergyStaff.Connection.Open()
updateClergyStaff.ExecuteNonQuery()
Response.Write(updateClergyStaff.ExecuteNonQuery.)
updateClergyStaff.Connection.Close()
''After updating data fill grid with updated info
and return to normal state
dgStaff.EditItemIndex = -1
daStaff.Fill(DsStaff1)
dgStaff.DataBind()
End Sub
推荐答案
我认为这是你的数据集,所以我期待a
dgStaff.Datasource = DsStaff
或者那里的东西
Cor
I assume that that is your dataset so I would expect a
dgStaff.Datasource = DsStaff
Or something there
Cor
这篇关于Datagrid更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!