Continually Improving.... let us know how support@devdiamond.net Sign in | Sign up
home articles news blog forum  

 
 


 
Skip Navigation LinksHome > Article > SQL Basics :: Update records in a database
SQL Basics :: Update records in a database
Abstract :
Here real examples using the Update Statement to update some data on a table.

Views : 3856
Published : Monday, January 21, 2002
By
HyperLink

Avarage Rating :
Page Page 1 of 1

'Do database connection
'Declare variables
sql = "update MyTable set"
sql = sql & "Field1 = '" & VAR1 & "',"
sql = sql & "Field2 = '" & VAR2 & "',"
sql = sql & "Field3 = '" & VAR3 & "' "
sql = sql & "where Field4 = '" & VAR4 & "'"
Conn.Execute(sql)


      The first thing that this code does is point to the table that is going to be updated. In this case it is a table that is called MyTable. You will need to rename this to the name of the table you are trying to update. FieldX is the actual name of the field that you are working with, so don't forget to change those.

      Notice that the last column to be updated has a " " at the end instead of a ",". Then the last line tells the script exactly what record to update. Here is another example of what the "where Field4 = " line could be:

sql = sql & "Where MemberUserId = '" & MemberId & "'"


About Author

        Yasir Send Feedback
        Yasir is a .NET expert, with over 5 years experience in Microsoft Technologies, 8 years overall programming experience, he is the owner, founder & primary contributor of Minwar.com, and he also works as IT Director in the hospitality industry.