How to pass values from SQL to ASP.NET?

LiLo

Active member
Joined
Mar 10, 2006
Messages
33
Hi,

I am making a login web service. First a database is created. It has ID,username and password attributes.

I plan to use the SELECT statement to retrieve the user record from the database.

How do I enable the ASP.Net code to check the password attribute value returned by the SELECT statement?

And if there is no record found, what value does the SELECT statement return and how to make ASP.Net know about this value?
 
If you are Querying the DB then you could just use a select statement to retreive the columns from the DB and put the result into either a DataReader or a DataTable - a DataReader is probably the simplest way in this case though.

If there are no matching results then you will either have a DataTable with no records in it or a DataReader with no data.

Also how are you storing the password? As a rule you should hash the password and store that rather than putting plain text into the DB.
 
Hi, thanks for the reply.

About reading and comparing from dataset/datatable, could you elaborate more or provide a simple sample?
 
Code:
 Dim sqlconn as new SqlConnection(ConnectionString)
Dim sqlcomm as SqlCommand = sqlconn.CreateCommand()

        sqlcomm.CommandText = "your sql query"
sqlcomm.CommandType = CommandType.Text

        sqlcomm.Parameters.Add("@username", SqlDbType.VarChar, 50)
sqlcomm.Parameters("@username").Value = username

sqlconn.Open()
Dim dr as SqlDataReader = sqlcomm.ExecuteReader()
If dr.HasRows Then
dr.Read
If username=dr("username") and password=dr("password") then
UserIsAuth(something)
End If
End If
 
Back
Top