dlubonski
asked on
Updating Sql from form
I currently have a form that contains a combobox and a number of text boxes, that display information based upon a dataset that is filled at form load.
DsFacility.Clear()
daFacility.Fill(DsFacility )
All the text boxes are bound to display the value of a specific field in the dataset. When I select a different facility from the combobox all related data is displayed correctly in the associated text boxes (so if I change from facility A to facility B the facility ID field is updated and so on). I want to be able to make a change to a field such as the address text box and save it back to the database. I mostly use the designer and wizards as I'm still learning but I've tried the following which works on other forms where I use a datagrid and not individual fields.
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Try
daFacility.Update(DsFacili ty, "facility")
Catch ex As Exception
MessageBox.Show(ex.ToStrin g)
End Try
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Try
DsFacility.Facility.Reject Changes()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
I've also tried to use a sql query direct with no luck (I used the sqlconnection that I used on the form for the dataset)
SqlConnection1.Open()
daFacility.UpdateCommand.C ommandText = "UPDATE facility SET oid = '" & txtOid.Text & "', facstatus = '" & txtFacStatus.Text &
"faccap='" & txtFacCap.Text & "',facint='" & txtFacInt.Text & "',faccntyid='" & txtFacCntyId.Text & "' where facid='" & lblFacID.Text "'"
SqlConnection1.Close()
it's probably something simple but I've spent too much time already and need to move on.
Thanks,
DsFacility.Clear()
daFacility.Fill(DsFacility
All the text boxes are bound to display the value of a specific field in the dataset. When I select a different facility from the combobox all related data is displayed correctly in the associated text boxes (so if I change from facility A to facility B the facility ID field is updated and so on). I want to be able to make a change to a field such as the address text box and save it back to the database. I mostly use the designer and wizards as I'm still learning but I've tried the following which works on other forms where I use a datagrid and not individual fields.
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Try
daFacility.Update(DsFacili
Catch ex As Exception
MessageBox.Show(ex.ToStrin
End Try
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Try
DsFacility.Facility.Reject
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
I've also tried to use a sql query direct with no luck (I used the sqlconnection that I used on the form for the dataset)
SqlConnection1.Open()
daFacility.UpdateCommand.C
"faccap='" & txtFacCap.Text & "',facint='" & txtFacInt.Text & "',faccntyid='" & txtFacCntyId.Text & "' where facid='" & lblFacID.Text "'"
SqlConnection1.Close()
it's probably something simple but I've spent too much time already and need to move on.
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER