simple login form

  • Thread starter Thread starter nabil m
  • Start date Start date
N

nabil m

hi i am using vs.net with csharp -
i am trying to create a simple log in form
user id
password

on submit i run a param query to check if the userid and password exist if
yes i
would like to store to the contactusername in a session and rediret the user
to another page -

q: how do i check if the param select query returned a record and how do i
access the userid from my sql query to store it in a session("sessUserId")

thx
 
Nabil,

If all you need is one value from your query, then the
SqlCommand.ExecuteScalar() method is what you want to use.

Ex)
object result = new SqlCommand("SELECT [USER] FROM USERTABLE WHERE [USER] =
'" + someUser + "' AND [PASSWORD] = '" + somePassword +
"'","SomeConnectionString").ExecuteScalar();
if(result==DBNull)
throw new ApplicationException("Unknown User or Bad Password");
else
session("sessUserId") = (string)result;

Hope this helps. Obviously, you will need to change it around a bit so that
the command string has param placeholders rather than building the string
inline.

Happy Coding!

Wadih Pazos
Software Architect
Solutions@MBA
www.satmba.com
www.PaperSave.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top