Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Command is not working when dataset is populating fields

Status
Not open for further replies.

load3d

Programmer
Feb 27, 2008
117
US
Hello,
I have a form that on Page Load event populates all text box fields on the form with sql string and a dataset. The user can then change information in the fields and update. The data is pulled using the query string as identifieridentifier. All of that is working fine. However, once information is updated the user clicks save. Once the user clicks save it ignores the information that the user updated and updates the table with information populated from page load. The update command is working and updates the table, but ignoring the changes. What can I do to fix this? Attached is the code for Page Load and the on_click(update) event
 
Have you tried:
Code:
        '\\ THEN HERE IS THE ON CLICK CODE (VERY SIMPLE) 

        Dim Str As String
        Str = "UPDATE tbl_indirect SET Approval = '" & "Y" & "', Code = '" & Me.Code.Text & "', Starttime = '" & Me.StartTime.Text & "', Stoptime = '" & Me.StopTime.Text & "', Totaltime = '" & Me.TotalTime.Text & "', Status = '" & "Complete" & "', IncidentPacket= '" & Me.IncidentPacket.Text & "', Approvalby = '" & NTUser & "', ApprovalDT = '" & Now() & "', modifiedby = '" & NTUser & "', modifiedDT = '" & Now() & "'  WHERE (ID = '" & Me.ID.Text & "')"

        [blue]Dim updater As New System.Data.SqlClient.SqlCommand(Str, Me.SqlConnection)[/blue]
        'Me.SQLDataAdapter2.UpdateCommand = New SqlCommand(Str, Me.SqlConnection)
        '---------------------------------------------------------------------------------
        Me.SqlConnection.Open()
        [blue]updater.ExecuteNonQuery()[/blue]
        'Me.SQLDataAdapter2.UpdateCommand.ExecuteNonQuery()
        Me.SqlConnection.Close()
?

Hoe this helps.
 
Is your SQLConnection closed or still open when you try to update. Also, you could simplify your code a bit:
Code:
Approval = '" & "Y" & "'
change to:
Approval = 'Y'
(this could also be done for status)

If at first you don't succeed, then sky diving wasn't meant for you!
 

Since you use the term "Page Load", I assume this is a Web form not a Windows form. If that is indeed the case, I strongly recommend you use parameters to do ANY database activity (Insert, Update, Delete). The way you have it set up now - taking input directly from controls and concatenating it into the SQL statement - is extremely vulnerable to a SQL Injection attack.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top