Fully Editable Datagrid - Update Command does not make updates

J

juustagirl

There is only one editable field on my datagrid ... a combo box.

The data displays correctly. I have a button to make all the changes
.... but they are never written back to my Access database.

I have tried Response.write lines to see that I get the correct value
for Id and Status for my command. I do not get any errors, but the
changes are not made to the database!?!?




Sub btnSaveAll_Click(sender As Object, e As EventArgs)
'save all updates made to datagrid
'Create connection and command objects
Dim myConnection as New oledbConnection(ConnectionString)
Dim updateSQL as String = "UPDATE Lead SET Status = @Status WHERE
LeadID = @ID"
myConnection.open()
Dim myCommand as New oledbCommand(updateSQL, myConnection)

Dim dgi as DataGridItem
For Each dgi in DataGrid1.Items
'Read in the Primary Key Field
Dim id as Integer =
Convert.ToInt32(DataGrid1.DataKeys(dgi.ItemIndex))
Dim status as String = CType(dgi.FindControl("cmbStatuses"),
DropDownList).Text


'Issue an UPDATE statement...
updateSQL = "UPDATE Lead SET Status = @Status WHERE LeadID =
@ID"

myCommand.Parameters.Clear()
myCommand.Parameters.Add("@id", id)
myCommand.Parameters.Add("@Status", status)


myCommand.ExecuteNonQuery()



Next

End Sub
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top