|
-
Jun 17th, 2007, 12:05 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Evaluating an expression with a paramater? ASP.Net/C#/SQL
I noticed that when I get to the line
if (usrNmeLbl.Text == usr)
that if the database couldn't get the username to match to an existing user that that check of the usr at that if statement will be skipped. I guess because of an unseen error from the reader that it just handles itself. I see that I need to do a check sooner as to whether the usr matches the textbox name. I am guessing I must somehow check that the paramater @usrnmeLbl is returning a value other than null? If so, how? Or some other way?
SqlCommand comm = new SqlCommand("SELECT * FROM UsrTbl, RelativeTable, IP_Table WHERE RelativeTable.UserID IN (SELECT UserID FROM UsrTbl WHERE UserName = @usrnmeLbl)", conn);
comm.Parameters.AddWithValue("@usrnmeLbl", usrNmeLbl.Text);
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
string usr = reader["UserName"].ToString();
usr = usr.TrimEnd();
string pss = reader["Password"].ToString();
pss = pss.TrimEnd();
if (usrNmeLbl.Text == usr)
I ask this because if I do an else for my if statement, the if is never reached under this condition and the else never gets triggered.
Thanks so much in advance.
-
Jun 17th, 2007, 11:42 PM
#2
Thread Starter
Hyperactive Member
Re: Evaluating an expression with a paramater? ASP.Net/C#/SQL
I decided to use:
if (reader.Read() != false)
It worked out!
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
|