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

syntax for sql server and asp update query 1

Status
Not open for further replies.

JacobTechy

Programmer
Apr 14, 2005
181
US
I have a textarea box named textarea in a form called NewsText. I am trying to update my sql server db called db1.
The table name is newstble and the column is news. I need to update the news record with what the user inputs into the textarea box but I cannot seem to get the syntax correct for the query.
Code:
		 strSQL = "SELECT * FROM newstble;"
		 oRS.Open strSQL, oConn,1,1
		If Not oRS.EOF Then
		oRS.MoveFirst
        oConn.Execute = "UPDATE newstble SET news ='" request.form("NewsText") 
	
		
		 end if
	
		 oRS.Close
                 oRS = Nothing
		 oConn = Nothing
                 oConn.Close

I get this compilation error

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/submit.asp, line 93, column 46
oConn.Execute = "UPDATE newstble SET news ='" request.form("NewsText")
 
>[tt]oConn.Execute = "UPDATE newstble SET news ='" request.form("NewsText") [/tt]
[tt]oConn.Execute[highlight] [/highlight]"UPDATE newstble SET news ='" request.form("NewsText") [red]& "'"[/red][/tt]
 
I tried it but I get the error

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/submit.asp, line 93, column 46
oConn.Execute = "UPDATE newstble SET news ='" request.form("NewsText") & "'"
---------------------------------------------^
 
I missed out another &, my bad!
[tt]oConn.Execute "UPDATE newstble SET news ='" [red]&[/red] request.form("NewsText") & "'"[/tt]
 
I dont know if you can help but when I submit my input text the record data changes to blank or null.
 
You have to set the update to specific subset of records (where). The syntax being:

[tt] UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
[/tt]
Beef it up, the sql statement?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top