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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Statement

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, may i check with you all that is the following code is correct!

And i have an enquiry. If i want to UPDATE 2 datas at the same time, how is the UPDATE statement going to be like.



<%@ Language=VBScript %>
<%Option Explicit%>

<HTML>

<HEAD>

<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>

</HEAD>

<BODY><!--#include file=&quot;adovbs.inc&quot;-->



<%

Dim DataConn ' ADO connection object
Dim sql_update, ConnString, objRs
Dim myName, myUserID, myPwd, myDept, myYr, myEmail, SQL

myName = request(&quot;text1&quot;)
myUserID = request(&quot;text2&quot;)
myPwd = request(&quot;password1&quot;)
myDept = request(&quot;select1&quot;)
myYr = request(&quot;radio1&quot;)
myEmail= request(&quot;text3&quot;)

Set DataConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
ConnString=&quot;driver={sql server};server=Omega; database=update;DSN=localserver;PWD=;UID=sa;&quot;
DataConn.Open ConnString
Set objRs=server.CreateObject (&quot;ADODB.Recordset&quot;)


sqlstr=UPDATE TABLE &quot;UP_TABLE&quot;
SET (&quot;NameID&quot;, &quot;UserID&quot;, &quot;password&quot;, &quot;yearinfo&quot; ,&quot;email&quot;) = (&quot;' & myNameID & '&quot; , &quot;' & myUserID & '&quot;, &quot;' & myPwd & '&quot;, &quot;' & myYr & '&quot;, &quot;' & myEmail & '&quot;)
WHERE department=&quot;'myDept '&quot;

DataConn.Execute (sqlstr)


objRs.Open sqlstr,DataConn



Any help will be appreciated! LOL
 
and update statement looks like this:

UPDATE tableName SET col1 = val1 , col2 = val2 WHERE someCol = someVal

penny.gif
penny.gif
 
Oops, what i meant is that UPDATE 2 tables in the same database.


Sorry for the confusion!!!LOL
 
Then you need two update-statements...

This line:

Code:
sqlstr=UPDATE TABLE &quot;UP_TABLE&quot;
SET (&quot;NameID&quot;, &quot;UserID&quot;, &quot;password&quot;, &quot;yearinfo&quot; ,&quot;email&quot;) = (&quot;' & myNameID & '&quot; , &quot;' & myUserID & '&quot;, &quot;' & myPwd & '&quot;, &quot;' & myYr & '&quot;, &quot;' & myEmail & '&quot;)
WHERE department=&quot;'myDept '&quot;

is slightly wrong ;-)

It probably should be something like:
Code:
strSQL=&quot;UPDATE TABLE UP_TABLE SET (NameID, UserID, password, yearinfo ,email) VALUES (&quot; & myNameID & &quot;, &quot; & myUserID & &quot;, '&quot; & myPwd & &quot;', &quot; & myYr & &quot;, '&quot; & myEmail & &quot;') WHERE department=&quot; & myDept

I assume that the fields NameId, UserId, YearInfo and Department are integers, if they are strings you need apostrophes around them as well...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top