Datagrid更新问题 [英] Datagrid Update problem

查看:46
本文介绍了Datagrid更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好...我在更新数据网格时遇到问题。

我的代码中的所有内容看起来都不错,所以我不知所措。我可以

点击更新,网格将重新绑定...但不是我的

更新数据。我没有在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

推荐答案

Brett,


我看到很多,但是我看不到的是你设置的地方新的带有数据源的
数据集作为数据源?


Cor

Brett,

I see a lot, however what I don''t see is where you set that new readed
dataset to your datagrid as a datasource?

Cor


嗨Cor ...感谢您的回复......


数据源是否由执行者查询更新?

如果没有,我该怎么办?关于设置它?
Hi Cor... Thanks for the response....

Doesnt the datasource get updated by the executenonquery??
If not, How would I go about setting it?


Brett,


我看到你这样做了。
Brett,

I see that you do this.
dgStaff。 EditItemIndex = -1
daStaff.Fill(DsStaff1)
dgStaff.DataBind()
dgStaff.EditItemIndex = -1
daStaff.Fill(DsStaff1)
dgStaff.DataBind()




我认为这是你的数据集,所以我期待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更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆