Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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
  #31 (permalink)  
Old September 11th, 2003, 11:08 AM
Authorized User
 
Join Date: Sep 2003
Location: Waco, TX, .
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to TnTandyO Send a message via Yahoo to TnTandyO
Default

Sorry I guess I'm just being a girl and a little to sensitive. :)

ok, It had some issues with the date and time field.. thinking maybe because they are numbers, so I took those out of the query.. the it tells me Sfname is not updateable.
I have another form that lets me add to this database, so if I can add to it shouldnt I be able to update? Or is sfname the problem, since I dont have a field in my database named sFname ect..
Reply With Quote
  #32 (permalink)  
Old September 11th, 2003, 11:19 AM
Authorized User
 
Join Date: Sep 2003
Location: Waco, TX, .
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to TnTandyO Send a message via Yahoo to TnTandyO
Default

Hey hey I got it to work... had an sFname where no s should be....
grrrr 24 hour on one s...
but date and time are not working.. I took them out it works fine. (have an images issue but I think I can fix that. :))
Reply With Quote
  #33 (permalink)  
Old September 11th, 2003, 01:16 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yoohoo!!!!!

Congratulations.

Bloody sFName again ;) It's partly my fault. "Old school programming" dictated Hungarian Notation", where each variable was prefixed with 1 or more letters to indicate its type, like sName (for a string), iLoopCount (for an Integer) and so on.

However, it's not common practice to do that in the database, so your field names didn't match. Nowadays, using this way of naming your variables is less common, especially in strongly typed languages (as you can see from their type what they are supposed to be). FirstName, LastName etc are much more user-friendly and easier to read then sFName.....

The date issue may be caused by the way you insert the date. In Access, SQL Server and other databases, you can insert your date in the ISO format: YYYYMMDD, so today would be 20030911

This way, the database will understand the date correctly.

This page will tell you more about that.

One other issue you need to fix: Replacing single ticks in your code. Suppose somebody types this in the name field: O'Brien

As soon as that happens, your code will break as the last ' will be interpreted as the closing delimiter for your SQL value. So, if you expect your data will contain this character, fix it by escaping it (put another ' in front of it):

sFName = Replace(sFName, "'", "''")

The last part actually contains two apostrophes. Now the name will look like this:

O''Brien

When you pass that to the database, it will end up as O'Brien in the column FName.

Look here for more info.

(I am telling you this now, as I am sure you'll run into this pretty soon).

Cheers and good luck, sensitive girl ;)

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #34 (permalink)  
Old September 11th, 2003, 01:36 PM
Authorized User
 
Join Date: Sep 2003
Location: Waco, TX, .
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to TnTandyO Send a message via Yahoo to TnTandyO
Default

Imar,
Preventive maintenance ... Thanks for that heads-up.
I guess I better do that with all of the text fields..
At this point I think I'm done with this program, unless I cause errors with that replace stuff ;) Have a few bells and whistles to add(the fun part).

Thanks for all your help, and if you don't see me back here for a while you can assume the program is working well, and I took a much needed break from this computer! :) If I can find some where to ftp this too once I'm done would you like to see it?
Take care,
Tandy
Reply With Quote
  #35 (permalink)  
Old September 11th, 2003, 02:02 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yeah, I'd like that. It would be nice to see how it ended up.
If it's too much trouble, though, don't bother. Getting your site to work on another location (at a remote host) might open up a can of worms big enough for another three page thread. ("What do you mean, it won't run at the production server? It runs fine on my development workstation....") :-)

Take some rest before you get square eyes......

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #36 (permalink)  
Old September 11th, 2003, 03:09 PM
Authorized User
 
Join Date: Sep 2003
Location: Waco, TX, .
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to TnTandyO Send a message via Yahoo to TnTandyO
Default

:( I'm sorry for asking so many questions, As you can tell I'm pretty new at this. In fact this would be my 2nd time messing with this stuff.
I have tried to figure out where to put
sFName = Replace(sFName, "'", "''")
but it doesn't seem to make a difference.

Square eyes... you mean they are not supposed to be this way? Oh no!! haha.
Reply With Quote
  #37 (permalink)  
Old September 11th, 2003, 04:32 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

:) I know what you mean. I have been staring at a computer screen for the past couple of days as well. Just too busy to do something else...

Oh well, here goes:
Let's look at your SQL UPDATE statement:
Code:
strSQL = "UPDATE tblIThelp SET " _
        & "sFname = '" & (Request.Form("Fname")) & "', " _
        & "Lname = '" & (Request.Form("Lname")) & "', " _
        & "Email = '" & (Request.Form("email")) & "', " _
        & "phone = '" & (Request.Form("phone")) & "', " _
        & "dept = '" & (Request.Form("dept")) & "', " _
        & "repeat = '" & (Request.Form("repeat")) & "', " _
        & "priority = '" & (Request.Form("priority")) & "', " _
        & "Comment = '" & (Request.Form("comment")) & "', " _
        & "notes = '" & (Request.Form("notes")) & "', " _
        & "tech = '" & (Request.Form("tech")) & "', " _
        & "date = '" & (Request.Form("date")) & "', " _
        & "time = '" & (Request.Form("time")) & "', " _
        & "solved = '" & (Request.Form("solved")) & "' " _
        & "WHERE (id = " & intID & ")"
        The best place to put the replace, is right around the Request.Form thingies:
Code:
strSQL = "UPDATE tblIThelp SET " _
Code:
        & "Fname = '" & Replace((Request.Form("Fname")), "'", "''") & "', " _
        & "Lname = '" & Replace((Request.Form("Lname")), "'", "''") & "', " _
  etc. etc, more UPDATE statement here (I left that out)
  Personally, I find this kind of code a bit messy and difficult to read and I prefer to write it like this:
Code:
' Declare
Code:
Dim sFName
Dim sLName

' Assign
sFName = Request.Form("FName")
sLName = Request.Form("LName")

' Modify / fix
sFName = Replace(sFName, "'", "''")
sLName = Replace(sLName, "'", "''")
This requires more steps, but IMO it's easier to read, understand and modify.

Even better would be this (as indicated by the link I posted):

Place the following function somewhere on your page, or put it in an include file for easy access:
Code:
Function FixSQL(ByVal SQLStatement)
  If Len(SQLStatement) > 0 Then
    FixSQL = Replace(SQLStatement, "'", "''")
  Else
    FixSQL = ""
  End If
End Function
With this function in your page, replacing the values is as easy as this:
Code:
strSQL = "UPDATE tblIThelp SET " _
        & "Fname = '" & FixSQL((Request.Form("Fname"))) & "', " _
        & "Lname = '" & FixSQL((Request.Form("Lname"))) & "', " _
        or, in my preferred "verbose coding style":
Code:
' Assign
Code:
sFName = Request.Form("FName")
sLName = Request.Form("LName")

' Modify / fix
sFName = FixSQL(sFName)
sLName = FixSQL(sLName)
Does that make sense??

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #38 (permalink)  
Old September 11th, 2003, 06:31 PM
Authorized User
 
Join Date: Sep 2003
Location: Waco, TX, .
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to TnTandyO Send a message via Yahoo to TnTandyO
Default

Thanks, that makes sense.... I'll give it a shot in the morning. Just don't have the heart for any more tonight.......
Did I keep you that busy? lol, duh!!
Thanks
TAndy
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
How to Edit record right after it was Inserted? aladov ASP.NET 2.0 Professional 4 December 11th, 2007 03:18 PM
Adding a blank record to a grid (in edit-mode) ColSandrs ASP.NET 1.0 and 1.1 Basics 1 December 21st, 2005 08:42 AM
Edit record help dbartelt Access 4 November 9th, 2005 06:02 PM
Update or CancelUpdate without AddNew or Edit ru1 Access 1 October 15th, 2005 02:24 PM
edit, update method life_s Ng ASP.NET 1.0 and 1.1 Basics 5 August 19th, 2003 10:45 PM



All times are GMT -4. The time now is 07:46 PM.


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