B
Brett
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
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