I am trying to use an ASP script to change a database yes/no value from no to yes. It is probably simple, but I can't seem to get it to work. Can anyone give me an idea of how to do this?
Databse is Access, it is a field in a table in the access database that has a yes/no data type. my query starts like this "update Customers set DeleteCode =..." Customers is the Table and DeleteCode is the table field.
Here is my line of code that has a problem. What is wrong with it? I keep getting this error. Anyone shed some light here?
try: var mySQL = "update Customers set DeleteCode = 'True' where Number = '" + Request.Form("Number") + "'"; Code (markup):
hey are you doing that in VBScript? if so then replace the + with & var mySQL = "update Customers set DeleteCode = 'Yes' where Number = '" & Request.Form("Number") & "'"; If Number is integer you don't need the ' ' around request.Form("Number")
the yes/no field in access is actually a bit, not the word yes or no. in access it is either false (no) or true(yes) If Number is an actual data type of NUMBER, not a TEXT or MEMO then you don't need the two sets of quotes. If it isn't, you do. to set to yes: var mySQL = "update Customers set DeleteCode = TRUE where Number = " & Request.Form("Number") to set to no var mySQL = "update Customers set DeleteCode = FALSE where Number = " & Request.Form("Number")
Hope it works... If you're anal, like I am, and like everything to balance out, you can still put quotes on the end by putting two next to each other: var mySQL = "update Customers set DeleteCode = FALSE where Number = " & Request.Form("Number") &""
I got it to finally work with this code... var mySQL = "update Customers set DeleteCode = TRUE where Number = " + Request.Form("Number") Thanks for the help everyone. I guess I need to get a better book.
I don't get it at all. What's the point to the last pair of double quotes? You said it had something to do with balance, but it balanced out quite a ways before. This may sound like I'm being sarcastic. I'm 100% not. I'm just trying to understand what you're doing. Regards, James
Unless computer books are really cheap wherever you're living, that's probably not the way to go. You need to write more code. (So do I, for that matter). It sounds to me as though books have taken you about as far as you're going to go. It's time to spread your wings, hop out of the nest, and start doing something with your code. That's just my impression, of course. And I'll be the first to admit that I'm most likely wrong.
Don't let me answer for ishopHQ, he may mean something different, but what i feel like he means here is basically, while yes, the (& "") is redundant and unnecessary, it is nonetheless logical, i.e. the sql statement starts and ends with quotes, and you escape/reenter your sql statement in pairs. on a simple sql statement like this one it really seems entirely unnecessary, as anyone who works with sql knows you don't need the trailing & "". however, if you have a VERY complex sql statements with lots of nested inner joins, order by clauses, renamed variables, etc... and it's not working right, being sure that all ampersands, apostrophes, #'s, quotes, etc.... are accounted for in pairs can be useful in troubleshooting errors. But you're right, it's not needed at all, especially in something like this - however alot of programmers will go ahead and put it in as a matter of principle. too true. I need to write more as well... and i've been writing ASP code every day for over 3 years. Books will only take you so far - real world application and daily usage is the only way to go. TOTAL IMMERSION, BABY! lol VG
Ok, that makes sense. Thanks. I haven't seen that technique before. Then again, I haven't done much really complex SQL. (The only I've had a job that even got close, we had a DBA to write stored procedures for us. Cake).