Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Update SQL Statement Expand / Collapse
Author
Message
Posted Tuesday, September 16, 2008 7:25 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, October 24, 2008 3:16 AM
Points: 12, Visits: 35

I am creating some questions site by ASP, by filling in the answers in a table on SQL 2005 and passing to the next site.
I'm giving the user a kind of tracking (identity), wich the user is passing over from on Question site to the other by Request.Form.

On the first Site the user is filling the name, first name, time and the kind of identity

sql= "INSERT INTO web(first name ,name,identy,time)VALUES('" & first name & "','" & name & "','" & identy & "','" & time & "')"

this works fine!

No I would like to continue with an Update Statement.

sql = Update web Set answer1='" & answer1 & "' where identity ='" & identity &

It gives me just an Internet Error Message: The page can't be shown...
Post #570210
Posted Tuesday, September 16, 2008 7:40 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 9:34 AM
Points: 194, Visits: 1,154
I suspect that your browser is suppressing the real error message. You should look to see if Friendly HTTP Error messages is turned on.

Pertinent to this forum, what you are doing appears to be ripe for SQL injection. One of the basics is to use stored procedures and pass in parameters instead of building the ad-hoc SQL.

There are all sorts of best practices out there regarding ASP and SQL Server development. I strongly suggest that you visit a few of these websites before getting too far down this path.

Kyle
Post #570225
Posted Tuesday, September 16, 2008 7:40 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 1:42 PM
Points: 10,340, Visits: 13,341
If this is actually the line of code:

sql = Update web Set answer1='" & answer1 & "' where identity ='" & identity & 

Then it isn't going to work as you do not have an opening double-quote on the string and you are ending the line with the concatenation character.

Beyond that you are leaving yourself open to SQL Injection by using the methods you are using. At the very least you should be using a command object with parameters instead of a straight SQL string.





Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #570226
Posted Tuesday, September 16, 2008 7:49 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, October 24, 2008 3:16 AM
Points: 12, Visits: 35
It is obvious, the SQL Satement is wrong,
But I can't yet manage it the right way.

sql = "Update web Set antwort1="' & antwort1 & "' where erkennung='" & erkennung & "'"

It doesnt work too!


Can anybody help my aboout the Update Statement ?
Post #570235
Posted Tuesday, September 16, 2008 8:05 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 1:42 PM
Points: 10,340, Visits: 13,341
Have you viewed the SQL string that is built and verified that it is valid in SSMS? Just a Response.Write(SQL) so you can verify the string is bing built correctly would help. If your table and column names are correct then I can't see anything wrong with SQL Statement.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #570248
Posted Tuesday, September 16, 2008 8:11 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 9:34 AM
Points: 194, Visits: 1,154
Look at the quotes after "antwort1="

You have "' and I believe it should be '" .

Post #570256
Posted Tuesday, September 16, 2008 8:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, October 24, 2008 3:16 AM
Points: 12, Visits: 35
I am trying out:

Actually
sql = "Update web Set answer1='" & answer1 & "' where identity='" & identity & "'"

Gives the error message with
Response.Write (SQL)
Response.End



Update web Set answer11='gerste' where identity=''3597@10P136P12P125''

Wich is not yet working.
Post #570273
Posted Tuesday, September 16, 2008 8:53 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, November 14, 2014 12:37 PM
Points: 2,361, Visits: 6,752
Is this the output of your response.write?
Update web Set answer11='gerste' where identity=''3597@10P136P12P125''

I see double quotes in the identity part. Check the Identity part. Also if I am not mistaken Identity (Your Column Name) is a Keyword. Put a square bracket for IDENTITY.



-Roy
Post #570315
Posted Wednesday, September 17, 2008 3:10 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, October 24, 2008 3:16 AM
Points: 12, Visits: 35
identity is just a normal column, not the identifier, I know, it is probalbly not right to use this word as an normal column, since it it reserved as identifier.
I don't know how to make the square brackets.
What would the SQL Statement be ?
Post #570843
Posted Wednesday, September 17, 2008 3:35 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, October 24, 2008 3:16 AM
Points: 12, Visits: 35
I found the right SQL Statement.
sql = "Update web Set answer1='" & answer1 & "'" & " where identity=" & identity

Thanks a lot for your replies.
SQL seems to be very delicate.
Post #570860
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse