Update database from form

Results 1 to 3 of 3

Thread: Update database from form

  1. #1
    Join Date
    Dec 1969

    Default Update database from form

    I have a simple form to update records from the database but it&#039;s only working when I hard code the values into the update statement. If I try to get the new info from the form I don&#039;t get any error but the database doesn&#039;t get updated. <BR><BR>This is the code: <BR> <BR>strUpdate = "update prod_company SET company_name=@company_name, profile=@profile WHERE (co_id = " & coupdated & ")" <BR><BR>cmdUpdate = New sqlCommand(strUpdate, SqlConnection1) <BR><BR>cmdUpdate.Parameters.Add("@company_name" , company_name.Text) <BR>cmdUpdate.Parameters.Add("@profile", profile.Text) <BR> <BR>SqlConnection1.Open() <BR>cmdUpdate.ExecuteNonQuery() <BR>SqlConnection1.Close() <BR><BR>editLabel.Text = ": sucessfully updated" <BR><BR>However if I replace the strUpdate statement with: <BR><BR>strUpdate = "update prod_company SET company_name=&#039;123 co&#039;, profile=&#039;this is the new profile&#039; WHERE (co_id = " & coupdated & ")" <BR><BR>and comment out the "cmdUpdate.Parameters.Add" it works. <BR><BR>Any ideas???

  2. #2
    Join Date
    Dec 1969

    Default one post is enough thanks....


  3. #3
    Join Date
    Dec 1969

    Default RE: Update database from form

    Finally one I can answer...<BR><BR>The problem is you are passing the SQL perameters as part of the string. and it it taking them literally. Here is how I would do it.<BR><BR>strUpdate = "update prod_company SET company_name=&#039;" & @company_name & "&#039;, profile=&#039;" & @profile & "&#039; WHERE (co_id = " & coupdated & ")" <BR><BR>I hope this helps.<BR><BR>Let me know!<BR><BR>Ron

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts