Working with ASP and SQL

Sharky Forums


Results 1 to 5 of 5

Thread: Working with ASP and SQL

  1. #1
    Reef Shark Nephalim's Avatar
    Join Date
    Nov 2000
    Location
    Michigan
    Posts
    463

    Post Working with ASP and SQL

    Hello All: I haven't been on in a LOOOONG time. Anywho, I've been trying to figure out ASP and SQL and have run into this problem. I am trying to write a page that retrieves data from one specific recordset and fills out the page according to that recordset, whichever the user chooses it to be. My method includes a SQL request something like this: ("SELECT * FROM table WHERE variable = x") , where x is the user specified variable. Unfortunately, I can only get it to work if x is instead a string, such as 'x', instead. Can anyone help me here? By the way, variable is the unique key for the table. HELP!

    ------------------
    ~ And that is my humble opinion.

    When I was a boy I was told that anybody could become President. Now I'm beginning to believe it. - Clarence Darrow

    The greatness of a woman’s power is measured in the size and amount of the balls she clutches in hand. -Me

    "Tink"
    1 GHz Tbird on A7V, 128MB PC133 RAM, Samsung 19" 900IFT, Radeon 64MB DDR VIVO, SB Live! MP3+, 42.9GB IBM HDD, Plexwriter 8/4/32, 3C905CTXM nic, Intellimouse Explorer
    ~ And that is my humble opinion.

    When I was a boy I was told that anybody could become President. Now I'm beginning to believe it. - Clarence Darrow

    The greatness of a woman’s power is measured in the size and amount of the balls she clutches in hand. -Nephalim

    "Tink"
    1700+ XP on A7N8X, 768MB PC2700 DDRRAM, Samsung 19" 900IFT, Radeon 64MB DDR VIVO, SB Live! MP3+, 42.9GB IBM HDD, Plexwriter 8/4/32, 3C905CTXM NIC

    "Hermes"
    Dell Inspiron 8200, 1.7 GHz P4, 512MB DDRRAM, 30GB HDD, DVDROM, Geforce4 Go 64MB

  2. #2
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    I'm not entirely sure I understand your situation from the post above, but this sounds like you're a little new to SQL statements.

    If you want to say:
    SELECT *
    FROM table
    WHERE variable = x


    And if X is a string (Anything other than a raw digit), than you should have single quotes around x.

    Perhaps if you try to either reword your question or give us some more info I can catch your drift a little better :P


  3. #3
    Reef Shark Pestilence's Avatar
    Join Date
    Dec 2000
    Location
    Hickville, USA. :(
    Posts
    353

    Post

    To be more technically specific its double quotes on both sides of a single quote and then an & and then the variable and then another & and a single quote with double quotes on each side again. But I use that when I deal with some session variables. And I don;t even know if that would apply either. Grizzly is right in saying you should give us some more details.

    ------------------
    (\__/) See the bunny.
    (='.'=) Hear the bunny.
    (") (") Pet the bunny.

    BE the bunny.

    Data Structure programming assignment solutions found here! http://www.sa.sc.edu/cp/java/
    By Yours truly.
    God damnit, better graphics != revolutionary gaming! Get it through your skull!

  4. #4
    Reef Shark Nephalim's Avatar
    Join Date
    Nov 2000
    Location
    Michigan
    Posts
    463

    Post

    Much thanks to both of you, though I have figured it out. Nonetheless, just to clarify:

    My old statement was:
    ("SELECT * FROM table WHERE variable = x")

    However, Pestilence was correct in his statement:
    ("SELECT * FROM table WHERE variable = '" & x & "' ")

    I have since used the second method, which works... but is there a better way using SQL or just plain VBScript? It is true, I have NEVER used SQL before. There is no time like the present to learn something new!

    ------------------
    ~ And that is my humble opinion.

    When I was a boy I was told that anybody could become President. Now I'm beginning to believe it. - Clarence Darrow

    The greatness of a woman’s power is measured in the size and amount of the balls she clutches in hand. -Me

    "Tink"
    1 GHz Tbird on A7V, 128MB PC133 RAM, Samsung 19" 900IFT, Radeon 64MB DDR VIVO, SB Live! MP3+, 42.9GB IBM HDD, Plexwriter 8/4/32, 3C905CTXM nic, Intellimouse Explorer
    ~ And that is my humble opinion.

    When I was a boy I was told that anybody could become President. Now I'm beginning to believe it. - Clarence Darrow

    The greatness of a woman’s power is measured in the size and amount of the balls she clutches in hand. -Nephalim

    "Tink"
    1700+ XP on A7N8X, 768MB PC2700 DDRRAM, Samsung 19" 900IFT, Radeon 64MB DDR VIVO, SB Live! MP3+, 42.9GB IBM HDD, Plexwriter 8/4/32, 3C905CTXM NIC

    "Hermes"
    Dell Inspiron 8200, 1.7 GHz P4, 512MB DDRRAM, 30GB HDD, DVDROM, Geforce4 Go 64MB

  5. #5
    Tiger Shark
    Join Date
    Feb 2001
    Location
    NJ, got a problem with that?
    Posts
    714

    Post

    Glad you figured it out. Of course, that line won't work if the field is Numeric, then you'd have to lose the single quotes. Nope, that's pretty much it when it comes to ASP and SQL. I recommend you use this method though:
    dim strSql
    strSql="SELECT * FROM Table WHERE variable =" & x & ""
    rs.open strSql, (connectionstring)
    That way, you can put a Response.Write strSql before opening the recordset and troubleshoot your SQL statement better.
    I also recommend visiting http://www.4guysfromrolla.com , they have a large number of articles on ASP and SQL, as well as a forum that's been helping me out a lot.

    ------------------
    "My other car is also a Porsche"
    -------------------------
    Abit BH6, rev. 1.01
    PIII-750@931
    256MB PC133 Crucial RAM
    Hercules Prophet 4500
    Diamond Monster MX300 w. Vortex 2 v.2048 drivers
    DirectX 8.0a
    "My other car is also a Porsche"
    -------------------------
    PIV-3.0GHz, 800MHz FSB; 1GB 400MHz SDRAM; Ati Radeon 9800 Pro; SB Audigy 2; Windows XP SP1
    Old rig: Abit BH6, rev. 1.01; PIII-750@931; 256MB PC133 Crucial RAM; Hercules Prophet 4500; Diamond Monster MX300; DirectX 8.0a; 60 GB IBM Deskstar 60XP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •