|
-
Feb 2nd, 2005, 10:41 AM
#1
Thread Starter
Addicted Member
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:
<%@ Page Language = "VB" Trace = "true" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Data.SqlClient" %>
<Script Runat="server">
Function Scriptname as string
Dim strURL,aryURL
strURL = Request.ServerVariables("SCRIPT_NAME")
aryURL = Split(strURL, "/", -1, 1)
Scriptname = (aryURL(ubound(aryURL)))
End Function
Sub Page_Load
'DB stuff
Dim SQLcon As SqlConnection, SQLcmd as SqlCommand, SQLread as SqlDataReader
SQLcon = New SqlConnection ( "Server=xxx.mysite4now.com;uid=xxx;pwd=xxx;database=xxx")
SQLcon.Open()
SQLcmd = New SqlCommand( "SELECT dir FROM NetFile WHERE user='core33' AND pass='test112'", SQLcon )
SQLread = SQLcmd.ExecuteReader()
While SQLread.Read()
Response.Write( SQLRead( "dir" ) )
End While
SQLread.Close()
SQLcon.Close()
End Sub
</script>
-
Feb 2nd, 2005, 10:47 AM
#2
Frenzied Member
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.
-
Feb 4th, 2005, 07:51 AM
#3
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
-
Feb 6th, 2005, 10:26 AM
#4
PowerPoster
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.
-
Feb 7th, 2005, 05:24 AM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|