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