Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 7th, 2007, 04:03 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default UPDATE statement

hie guys, im having trouble with updating an access database. Here is my code below. userAns and QuesNo are fields in the database and userAns and ques are variables that I have declared and will get values from textboxes etc. For some reason the details are not being updated into the database

        Dim objConn As New OleDbConnection _
            ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "User ID=Admin;" & _
            "Data Source=db2.mdb")
        objConn.Open()

        Dim objAdapter As New OleDbDataAdapter
        objAdapter.UpdateCommand = New OleDbCommand( _
            "UPDATE Ques_Table SET userAns= '" & userAns & "' Where QuesNo ='" & ques & "'", objConn)

        objConn.Close()

Reply With Quote
  #2 (permalink)  
Old March 7th, 2007, 04:06 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Write out your SQL statement, are all the values as they should be?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old March 7th, 2007, 04:10 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dim userAns As String
   userAns = yourAns.text
Dim ques As String
   ques = quesNumber.text

Dim objConn As New OleDbConnection _
            ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "User ID=Admin;" & _
            "Data Source=db2.mdb")
        objConn.Open()

        Dim objAdapter As New OleDbDataAdapter
        objAdapter.UpdateCommand = New OleDbCommand( _
            "UPDATE Ques_Table SET userAns= '" & userAns & "' Where QuesNo ='" & ques & "'", objConn)

        objConn.Close()

Reply With Quote
  #4 (permalink)  
Old March 7th, 2007, 04:13 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

im not sure about my syntax and quotes e.g.'" & userAns & "'

Reply With Quote
  #5 (permalink)  
Old March 7th, 2007, 04:33 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

thats not what i meant. Instead of executing the sql statement do:

Response.Write("UPDATE Ques_Table SET userAns= '" & userAns & "' Where QuesNo ='" & ques & "'")

Look at hte statement, does it produce the update statement you THINK its producing.

Also, by and large, when a table doesn't update the correct row, its normally because of a failure in your WHERE clause.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #6 (permalink)  
Old March 7th, 2007, 04:42 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when I put in Response.Write("UPDATE Ques_Table SET userAns= '" & userAns & "' Where QuesNo ='" & ques & "'") it say End of Statement expected. If I got you right do I simply replace "UPDATE Ques_Table SET userAns= '" & userAns & "' Where QuesNo ='" & ques & "'", objConn) with Response.Write("UPDATE Ques_Table SET userAns= '" & userAns & "' Where QuesNo ='" & ques & "'") ???


Reply With Quote
  #7 (permalink)  
Old March 7th, 2007, 04:50 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The response.write is for purposes of debugging only. Your sql statement is not executing correctly, so my suggestion is to look at the SQL string itself.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #8 (permalink)  
Old March 7th, 2007, 07:48 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What he means is do a response.write of ONLY the sql syntax, and then read it, it should have your values etc in there, with not syntax errors.

I think you should really think close about what your doing though. Your leaving it open to a SQL injection attack. Thats where someone puts malicious code into a text box, and on submit, it runs against your database and can update/delete/destroy things your not aware.

That being said I ran your query and got this.
UPDATE Ques_Table SET userAns= 'hello' Where QuesNo ='world'
and the query will work as long as everything else is how it should be, which means either your connection isnt happenign properly, or your columns are not spelled correctly or the 'types' are not varchar, and the compare is failing based on type.


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
update multiple columns in an update statement debbiecoates SQL Server 2000 1 August 17th, 2008 04:01 AM
Error when trying to use an UPDATE statement wayne62682 Access VBA 2 April 4th, 2006 07:50 PM
Update Statement some error thas123 ADO.NET 1 January 8th, 2006 10:30 AM
SQLDataAdapter's Update Statement bmains ADO.NET 5 May 7th, 2004 03:05 AM



All times are GMT -4. The time now is 11:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.