Results 1 to 5 of 5

Thread: SQL Command Problem

  1. #1

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169

    SQL Command Problem

    ok, i have a problem with a SQL command.

    I have created a table in my database called netfile with three column, user, pass, dir.

    When i run

    the command:

    SELECT dir FROM netfile WHERE user='core33' AND pass='test33'

    Nothing happens

    when i run;

    SELECT dir FROM netfile WHERE pass='test33'

    It returns correctly

    when i run;

    SELECT dir FROM netfile WHERE user='core33'

    Nothing Happens.


    Can someone look through this code and see why when i search for a record by the USER column it doesn't detect it but where i search via the PASS column it finds it???


    -----------------------------------------

    All the columns are 50,CHAR in the database


    VB Code:
    1. <%@ Page Language = "VB" Trace = "true" %>
    2. <%@ import Namespace="System.IO" %>
    3. <%@ import Namespace="System.Data.SqlClient" %>
    4.  
    5. <Script Runat="server">
    6.  
    7.     Function Scriptname as string
    8.         Dim strURL,aryURL
    9.         strURL = Request.ServerVariables("SCRIPT_NAME")
    10.         aryURL = Split(strURL, "/", -1, 1)
    11.         Scriptname = (aryURL(ubound(aryURL)))
    12.     End Function
    13.  
    14.  
    15.         Sub Page_Load
    16. 'DB stuff
    17.  
    18.         Dim SQLcon As SqlConnection, SQLcmd as SqlCommand, SQLread as SqlDataReader
    19.  
    20.         SQLcon = New SqlConnection ( "Server=xxx.mysite4now.com;uid=xxx;pwd=xxx;database=xxx")
    21.  
    22.         SQLcon.Open()
    23.  
    24.         SQLcmd = New SqlCommand( "SELECT dir FROM NetFile WHERE user='core33' AND pass='test112'", SQLcon )
    25.  
    26.         SQLread = SQLcmd.ExecuteReader()
    27.  
    28.         While SQLread.Read()
    29.  
    30.             Response.Write( SQLRead( "dir" ) )
    31.  
    32.         End While
    33.  
    34.         SQLread.Close()
    35.  
    36.         SQLcon.Close()
    37.        
    38.         End Sub
    39.  
    40. </script>

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: SQL Command Problem

    Not sure if this is the problem, as I didn't try it, but I believe that "user" is a keyword in Sql Server. Try using "SELECT [user]..." instead of "SELECT user...", or better yet, change the column name to something like UserName.

  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: SQL Command Problem

    Code:
    WHERE NetFile.User = 'core33'
    or
    Code:
    WHERE NetFile.[User] = 'core33'
    or
    Code:
    WHERE [User] = 'core33'
    I prefer the 1st method though.

    Woka

  4. #4
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    Re: SQL Command Problem

    Just to add to what Woka suggested, I would like to add that can do the same for the dir field as well.
    On second thoughts, if its possible for you to change the fields names in your database then its best to use field names which aint keywords.

  5. #5

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169

    Re: SQL Command Problem

    Thanks I got it, putting [ ] around USER fixed it. USER is a ASP.NET & SQL reserved word.

Posting Permissions

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



Click Here to Expand Forum to Full Width