Datagrid Update problem

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
 
C

Cor Ligthert

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
 
B

Brett

Hi Cor... Thanks for the response....

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

Cor Ligthert

Brett,

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

I assume that that is your dataset so I would expect a
dgStaff.Datasource = DsStaff

Or something there

Cor
 
G

Guest

Hi Cor...

dgStaff.Datasource = dsStaff1 is already being done in a
prior statement. The datagrid does fill, just not with my
updated data. Unless I need to refill it?? Do I need it in
a different spot maybe? THis one is driving me nuts, as I
dont really see anything wrong??
 
C

Cor Ligthert

Anonymous,

Just try it, I assume that this can be (one) of the reasons you don't see
the right information.

Cor
 
B

Brett

Facetious,

Tried it... same thing... :-(

Whats strange is that if i response.write the parameters
passed in they print out correctly (showing my changes).
So its got to be somewhere in the update itself??? Or in
the binding somewhere???

-Frustrated (Brett)
 
C

Cor Ligthert

Brett,

I don't understand your message. Is your actual database updated or is that
not?

What would than be strange that there is than not an error throwed when it
is not.

Cor
 
G

Guest

-----Original Message-----
Brett,

I don't understand your message. Is your actual database updated or is that
not?

What would than be strange that there is than not an error throwed when it
is not.

Cor
Cor,

Correct, The database is not getting updated. I would
think there should be an error too... but I hit update,
and the dataset rebinds to the grid without the updated
data... Strange :-( This is my first attempt at an update,
but from examples I have seen everthing looks to be in
place.

-Brett
 
C

Cor Ligthert

Brett,
updateClergyStaff.ExecuteNonQuery()
Response.Write(updateClergyStaff.ExecuteNonQuery.)
updateClergyStaff.Connection.Close()


What is that Response.Write a strange instruction espicaly that dot

I never did it this way, however can you change that for
\\\
try
updateClergyStaff.ExecuteNonQuery
catch ex as exception
response.redirect(ex.toString)
finally
updateClergyStaff.Connection.Close()
end try

///
Even when it was only to try now.

Cor
 
B

Brett

lol... oopss... that shouldnt be in there... That was a
pasted in response.write that somehow has the
executenonquery in it. sorry bout that./

-Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top