Cari Blog Ini

08 September 2011

Code for Create Login Using Module in ASP.NET

In "FormLogin.vb"

'-----------------------------------------------------------------

Imports System.Data
Imports System.Data.SqlClient

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Try
            _objConnection.Open()
            _strSQL = " exec AppC_SPC_CheckUsers '" & txtUserName.Text & "', '" & txtPassword.Text & "' "
            _objCommand.Connection = _objConnection
            _objCommand.CommandText() = _strSQL



            Dim _dr As SqlDataReader = _objCommand.ExecuteReader

            If _dr.Read = False Then
                MsgBox("Username and Password is not found", MsgBoxStyle.Critical, "Message")
                txtUserName.Clear()
                txtPassword.Clear()
                txtUserName.Focus()
            Else
                _userName = _dr.GetValue(0)
                _password = _dr.GetValue(1)
                MsgBox("...next form... " + _userName, MsgBoxStyle.OKOnly, "Message")

            End If
        Catch ex As Exception
            MsgBox("Error has found : " + ex.Message.ToString, MsgBoxStyle.Critical, "Message")
        Finally
            _objConnection.Close()

        End Try
'-----------------------------------------------------------------


In "Module.vb"

'-----------------------------------------------------------------
Imports System.Data
Imports System.Data.SqlClient

Module _Module
    Public _objConnection As SqlConnection = New SqlConnection("Data Source=dtbs;Initial Catalog=Testing;User Id=sa;Password=sasasa;")
    Public _objCommand As SqlCommand = New SqlCommand

    Public _strSQL As String
    Public _userName, _password As String
    Public _intResponse As Integer
End Module
'-----------------------------------------------------------------