473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

what is the data types I get from the database by SqlDataReader

24
I am using asp.net(C#) to build a login sys. I use the SqlDataReader to get the data from the data base to validate the user. but it always comes the password dosn't matches. but I tested to print the password get from the database and user input on the page, they are the same. can any one tell me why?

I use text box to get user input
like sting userpwd = textbox.text..ToString().Trim();

and SqlDataReader sdr = cmd.ExecuteReader();
.......
if(str["Password"]==userpwd){}
.......
in the database, the password type is char(16)
May 5 '08 #1
4 1226
Plater
7,872 Expert 4TB
Are you making sure to cast the str["Password"] object as a string?
Because if it's still referenced as an object, then it will do an object compare against the string (which would be false) and not a string comparison.
May 5 '08 #2
lucoin
24
Are you making sure to cast the str["Password"] object as a string?
Because if it's still referenced as an object, then it will do an object compare against the string (which would be false) and not a string comparison.


Thanks. That's the problem.

I forgot to add .Trim();
May 6 '08 #3
r035198x
13,262 8TB
Are you making sure to cast the str["Password"] object as a string?
Because if it's still referenced as an object, then it will do an object compare against the string (which would be false) and not a string comparison.
Actaully the == operator has the effect of calling ToString on the object so that == is done against two Strings. Thus for

Expand|Select|Wrap|Line Numbers
  1. object o = "object";
  2. string s = "object";
s == o returns true.

@OP calling Trim for password comparisons is rather odd. What if I want a password that ends with two spaces? I suggest you investigate where the extra spaces are coming from and solve that.
May 6 '08 #4
Plater
7,872 Expert 4TB
Actaully the == operator has the effect of calling ToString on the object so that == is done against two Strings.
Learn something new everyday.
May 6 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: shadow.demon | last post by:
G'day, I've separated my database calls into a separate dll, and return results from any database calls as a SqlDataReader (because of SQL Server use, it's nice and fast). However I'd like to be...
2
by: msn | last post by:
What is the best way to connect to a sql database in a asp.net page with Visual studio. An example would be great. Thanks Dave
2
by: TN Bella | last post by:
PLEASE HELP!! I am so far behind....and it doesn't help that I am learning all this stuff. I am using .net framework 1.0 from WebMatrix. These parameters get me all confused...someone please help!...
2
by: Glenn Venzke | last post by:
I'm trying to put together a web form that lists all current session information. The session info is stored in SQL server database (ASPState) and I'm trying to retreive and display using a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.