0

anyone can help me to connect to SQL server through vb.net using asp.net webform.. I have the database name Users and i want to use the database for the login page.. please help me..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ConnectionString As String 
    ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")
    Dim con As New SqlConnection(ConnectionString) 
    Dim cmd As New SqlCommand("Select UserId, Pwd from Users", con) 
    con.Open()
    Dim myreader As SqlDataReader
    myreader = cmd.ExecuteReader() 
    While myreader.Read()
        If TxtUserId.Text = myreader("UserId").ToString().Trim() 
           AndAlso TxtPwd.Text = myreader("Pwd").ToString().Trim() Then
            Session("UserId") = TxtUserId.Text 
            Response.Redirect("UserMyProfile.aspx") 
        Else 
            lblMsg.Visible = True 
            lblMsg.Text = "Inavalid UserId/Password" 
        End If
    End While
    con.Close() 
End Sub 
10
  • Google can help you... lots of examples startvbdotnet.com/ado/sqlserver.aspx Commented Mar 28, 2011 at 10:32
  • i have tried the code already.. but, when i debug, there are some errors.. i'm a beginner in asp.net.. Commented Mar 28, 2011 at 10:35
  • 2
    @tan keng: If you're getting specific errors, you can ask a question here about those errors. We're happy to help. Commented Mar 28, 2011 at 10:35
  • 1
    It's better to post what you have tried and what errors you are encountering, from that point you will get the help you need. Commented Mar 28, 2011 at 10:36
  • i tried that coding before.. but there are still some errors Commented Mar 28, 2011 at 10:41

1 Answer 1

1

There's no shortage of tutorials on the web for this, but a good starting point is here.

EDIT: Based on your comments above, it sounds like you're not importing the Namespace you need for the ADO.NET data objects. Try adding this to the class file:

Imports System.Data.SqlClient
Sign up to request clarification or add additional context in comments.

2 Comments

david, do u have some sample of asp.net web? i want to study more about asp.net since i'm newbie for asp.net
@tan keng: There's really no shortage of examples and tutorials online. Google can give you a lot more than I can. (Additionally, I'm not a very good teacher. My example applications won't be... beginner level.) Also, "I want to learn ASP.NET" is way too broad a topic for Stack Overflow. Specific questions, such as the code you posted and the errors you saw, are great here. But this isn't really a tutorial site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.