• Advertisement
Sign in to follow this  

C# and SQL: How do I programatically search for a value in a column?

This topic is 4142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have a C# program that uses a SQL database to store player information. In that database there is a table called Player. What I want to do is search for a specific value in the password column. Then when I find the row with that password get its ID information and log that player in. I am using C# Express Edition and SQL Server Express. So how can I programatically do the search? I have read around in MSDN for a good while and I can't seem to find anything relevant. Thanks in advance for any help/flames. :) Im hitting the sack so I won't be able to respond for a while. Been programming for 22 hours non-stop.

Share this post


Link to post
Share on other sites
Advertisement
Using an SQL query:

SELECT * FROM Player WHERE Player.password = [insert your password here]

This retrieves all rows with a given password.

Share this post


Link to post
Share on other sites
Thats a potentially dangerous way of logging people in.

It allows users to spam passwords with the intention of getting into someone else's account also means you could get in to another persons account if you accidentlly mistyped your password.

Better way to do it is match on username and password.

SELECT * FROM Player WHERE USERID = '<xxxxxx>' AND PASSWORD = '<xxxxx>'

or

SELECT COUNT (USERID) FROM Player WHERE USERID = '<xxxxxx>' AND PASSWORD = '<xxxxx>'
Then if count = 1 you know he has been found. You can then get the appropriate view of the player details you need.

1st example will do everything you need in one go because it will also get the additional information from the Player table 2nd one will only tell you if the correct username/password has been entered.


Replace USERID and PASSWORD with the appropriate fields in your database.



Hope this helps

Malal

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement