New to .NET

ASP.NET Web Application
VB.NET / SQL Server 2000

tblLogin in the database PCHL
txtUser, txtPass, and cmdRun

I've got a web form with 2 text boxes and a button. When the button is clicked by a user
I want the application to check the DB, find a match for txtUser in the column 'username' then check to see if it correlates with the text entered in txtPass and the column 'password 'in the DB. How would I go about writing the code behind for this button? Is there anything else I need to consider that I wouldn't have had to in VB6? Can anyone give me an example of code and/or some good resources for .NET beginners? Thanks

M Dub
Mike MillerSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

planoczCommented:
Hi,

Here is where I found good examples for getting started in VB.Net

.....http://msdn.microsoft.com/vbasic/downloads/samples/101samples.aspx

Link for ASP programs...

http://msdn.microsoft.com/asp.net/downloads/kits/default.aspx 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
You need to:

(1) Create SQLConnection object with the appropriate connection information to SQL Server database.
(2) Create SQLCommand object to query the table for the password for a particular user.
(3) SQLCommand.ExecuteScalar to return the password into a string variable.
(4) Check the value in the TextBox against the value returned from the database.

Things to think about:
(1) Stored procedure in SQL Server
(2) Encrypted passwords - stored hashed password, then encrypt the plain text password and compare.  This way you don't ever see the real password as plain text.

Bob
0
mani_saiCommented:
Here is the sample code:


1) you have to Import namespace first

Imports System.Data.SqlClient

2)'Button click event code:

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

'Retrive the values from textboxes
Dim Userid as string = Textbox1.Text
Dim Password as string = Textbox2.Text

'define the connection(use your sql server connection string)
Dim objconn As SqlConnection = New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;")

'opens a dataset
Dim ds As New DataSet

'open a dataadapter
Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from tbl_Login", objconn) 'use your table name

'Fill the dataset
da.Fill(ds)

'open the connection
objconn.Open()

'define a datarow
Dim LoginName As DataRow

'loop the dataset

For Each LoginName In ds.Tables(0).Rows

If  Userid  =  LoginName("LoginName")  and  Password  =  LoginName("Password") Then

'login success
Response.Redirect("WelcomePage.aspx")  'redirect to your page.

'Clean Up
dr.Close()
objconn.Close()

Exit Sub

Next


lblResult.Text = "You have entered incorrect Log-in ID/Password! Try Again!"

'Clean Up
dr.Close()
objconn.Close()
End Sub



0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

caball88Commented:
it sounds like you are tring to create a login form, this might be a little off topic but also investigate forms authentication. this is a great feature that will allow you to protect your aspx pages.
0
Mike MillerSoftware EngineerAuthor Commented:
mani_sai:

In your code...
What is 'dr'???
Was it your intention not to end your IF statement?


caball88:
It is sort of a login form. Really I'm just trying to learn how to connect to a DB and use the data in an application. Any relative example would help. I'm not necessarily trying to build a login page for an application. Just trying to learn :-)
0
planoczCommented:
The Links that I posted should serve your purpose.
0
mani_saiCommented:
Sorry for the typo Error.

dr stands for SQlDataReader.

Here is the modifed code.

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

'Retrive the values from textboxes
Dim Userid as string = Textbox1.Text
Dim Password as string = Textbox2.Text

'define the connection(use your sql server connection string)
Dim objconn As SqlConnection = New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;")

'opens a dataset
Dim ds As New DataSet

'open a dataadapter
Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from tbl_Login", objconn) 'use your table name

'open a sql datareader
Dim dr as SqlDataReader

'Fill the dataset
da.Fill(ds)

'open the connection
objconn.Open()

'define a datarow
Dim LoginName As DataRow

'loop the dataset

For Each LoginName In ds.Tables(0).Rows

If  Userid  =  LoginName("LoginName")  and  Password  =  LoginName("Password") Then

'login success
Response.Redirect("WelcomePage.aspx")  'redirect to your page.

'Clean Up
dr.Close()
objconn.Close()

Exit Sub  'exit the loop here if you find a match

End if

Next


lblResult.Text = "You have entered incorrect Log-in ID/Password! Try Again!"

'Clean Up
dr.Close()
objconn.Close()
End Sub


good Luck

0
mani_saiCommented:
Sorry please neglect my previous code.
Actually dr--datareader is not required  in this scenario.


Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

'Retrive the values from textboxes
Dim Userid as string = Textbox1.Text
Dim Password as string = Textbox2.Text

'define the connection(use your sql server connection string)
Dim objconn As SqlConnection = New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;")

'opens a dataset
Dim ds As New DataSet

'open a dataadapter
Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from tbl_Login", objconn) 'use your table name

'Fill the dataset
da.Fill(ds)

'open the connection
objconn.Open()

'define a datarow
Dim LoginName As DataRow

'loop the dataset

For Each LoginName In ds.Tables(0).Rows

If  Userid  =  LoginName("LoginName")  and  Password  =  LoginName("Password") Then

'login success
Response.Redirect("WelcomePage.aspx")  'redirect to your page if there is a match.

'Clean Up
objconn.Close()

Exit Sub  'exit the loop here if you find a match

End if

Next


lblResult.Text = "You have entered incorrect Log-in ID/Password! Try Again!"

'Clean Up
objconn.Close()
End Sub

good luck.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.