|
-
Aug 24th, 2012, 12:43 PM
#1
Thread Starter
New Member
Update Query On Save
Hi All,
I have made a form to process all the details of employees in the organisation, it has several fields, an edit and a save button. All fields are set as read only on the form load. When i click edit the fields become available for editing. When i click the save button i want it to update the tables in the database to the fields on the form. For some reason the update query does not run, there is no error it just doesn't update any data in the table. Any Ideas?
Do i need to use a dataset or is this fine?
Code:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection
conn.ConnectionString = ("Data Source=ALEX-LAPTOP\SQLEXPRESS;Initial Catalog=sldb;Integrated Security=True;Pooling=False")
Dim updateAdapter As New SqlClient.SqlDataAdapter
Dim sqlupdatequery = "UPDATE employee SET esr_no='" & txtEsr.Text & "', firstname='" & txtFirstname.Text & "', middlename='" & txtMiddlename.Text & "', lastname='" & txtLastname.Text & "', addressl1='" & txtAddress1.Text & "', addressl2='" & txtAddress2.Text & "', addressl3='" & txtAddress3.Text & "', addresscity='" & txtCity.Text & "', addresspostcode='" & txtPostcode.Text & "', addresscountry='" & txtCountry.Text & "', telephone='" & txtTelephone.Text & "', grade='" & cmbGrade.Text & "', speciality='" & cmbSpeciality.Text & "' WHERE sys_id='" & txtSysid.Text & "'"
Dim updatecommand As New SqlClient.SqlCommand
updatecommand.Connection = conn
updatecommand.CommandText = sqlupdatequery
updateAdapter.UpdateCommand = updatecommand
conn.Open()
updatecommand.ExecuteNonQuery()
conn.Close()
Me.txtEsr.ReadOnly = True
Me.txtFirstname.ReadOnly = True
Me.txtMiddlename.ReadOnly = True
Me.txtLastname.ReadOnly = True
Me.txtAddress1.ReadOnly = True
Me.txtAddress2.ReadOnly = True
Me.txtAddress3.ReadOnly = True
Me.txtCity.ReadOnly = True
Me.txtCountry.ReadOnly = True
Me.txtPostcode.ReadOnly = True
Me.txtTelephone.ReadOnly = True
Me.cmbGrade.DropDownStyle = ComboBoxStyle.DropDownList
Me.cmbSpeciality.DropDownStyle = ComboBoxStyle.DropDownList
End Sub
Thanks in advance!
Alex
-
Aug 27th, 2012, 07:16 AM
#2
Thread Starter
New Member
Re: Update Query On Save
Has anyone got any ideas ive had 90 views and no replies
-
Aug 27th, 2012, 07:27 AM
#3
Hyperactive Member
Re: Update Query On Save
Use a parameter when doing some sql query you can read the post of JM. follow the Retrieving data in my signature
-
Aug 27th, 2012, 07:29 AM
#4
Re: Update Query On Save
Try taking the value of sqlupdatequery and running it in the native database window. For example if it is MS SQL 2005 Enterprise Manager, MS SQL 200 Query Analyzer, etc. See if it works there first. One way is in the immeadiate window type:
?sqlupdatequery
Cut that in native SQL and see if it works. That will tell you if it is the way the statement is built or something else.
-
Aug 27th, 2012, 11:52 AM
#5
Thread Starter
New Member
Re: Update Query On Save
cheers for the replies! i have looked at JM's thread, i have a form with fields on but only view one record at a time, although the user should be able to search through records to find the relevant person. Would this count as multiple or single records to be updated? as i noticed on JM's thread it says:
retrieving a single record
Retrieving multiple records that will be read and discarded.
Retrieving multiple records for display that will not be updated.
Retrieving multiple records for display and editing, then saving the changes.
Saving changes directly to one or more records in the database.
I'm guessing its one of the last two but i'm not 100% on it as i require that multiple records are retrieved but only a single record is displayed and updated at a time.
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|