Solved

Password protected form

Posted on 2004-11-02
268 Views
Last Modified: 2010-04-23
Hi everyone I have 1 form , and I would like to set another one that will be password protected, so what I want is when I click my exe file that form1 is opened and I must enter username and password--- and then form2 (my main form) will be opened.

Is it possible to have on that 1st form  text boxes.

1st  username
2nd password

button that will include pass confirmation and form2 open.
button that will open form in which I will be able to change passes and add new users
And second problem , new form ( that will be opened with button on 1st form)or new textboxes where I can and new users and give them passes , or change old passes.
0
Question by:newbie22
    59 Comments
     
    LVL 28

    Expert Comment

    by:iboutchkine
    on a button click event

    if txtName.Text = "MyName" andalso txtPwd = "MyPwd" then
    Dim frmForm2 as New Form2()
    frmForm2.Show()  
    else
    msgbox("Not valid name and password")
    end if

    You can hardcode the name and password or keep them in external file like ini or in the database
    0
     
    LVL 27

    Expert Comment

    by:planocz
    If you want to real get heavy into security check code.....

    http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20787103.html
    0
     
    LVL 1

    Author Comment

    by:newbie22
    Ok and if I have this access database with 2 columns
    1st Username    2nd pass
    .
    .
    .

    and I have connected my database with form:

    Inherits System.Windows.Forms.Form

    Dim conn6 As New ADODB.Connection()
        Dim rcd6 As New ADODB.Recordset()

    windows. .......

    Private Sub Table1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            conn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\PASSWORD.mdb;"
            conn.Open()
            rcd.Open("SELECT * From Table1;", conn, 1, 3)
            While Not rcd.EOF
    ..

    How can I set that textbox1 and to textbox2 check username and pass from mdb file.

    THANKS
    0
     
    LVL 28

    Expert Comment

    by:iboutchkine
    First of all forget about recordset. DO it .NET way

     Dim cmd As New OleDbCommand
            Dim rdr As OleDbDataReader
            Dim sSQL As String = "Select * from Table1"
            dim b as boolean

            With cmd
                .Connection = cn
                .CommandText = sSQL
                .CommandTimeout = 0
                rdr = .ExecuteReader()
            End With
            Do While rdr.Read()
                if rdr("Name") = txtName.text andalso rdr("Pwd") = txtPwd.text then
                   b=true
                   exit do          
              end if          
            Loop
            rdr.Close()
            rdr = Nothing

    if b = true then
      'name and pwd found
    0
     
    LVL 1

    Author Comment

    by:newbie22
    and is it possible to hide pass in textbox2---like asterisk, or dots?
    0
     
    LVL 28

    Expert Comment

    by:iboutchkine
    yes. In the property of the textbox PasswordChar enter * (or whatever char you want)
    0
     
    LVL 1

    Author Comment

    by:newbie22
    this is underlined , a bit more help please


    Dim cmd As New OleDbCommand()
            Dim rdr As OleDbDataReader

    i need to put them here , right?:

    Inherits System.Windows.Forms.Form
    Dim cmd As New OleDbCommand()
            Dim rdr As OleDbDataReader
    0
     
    LVL 1

    Author Comment

    by:newbie22
    or here:

     Private Sub Table1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            conn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\db1.mdb;"
    Dim cmd As New OleDbCommand
            Dim rdr As OleDbDataReader
            Dim sSQL As String = "Select * from Table1"
            dim b as boolean
    ....


    THANKS
    0
     
    LVL 28

    Expert Comment

    by:iboutchkine
    Imports System.Data.Oledb


    dim cn as OleDbConnection
    Dim cmd as As New OleDbCommand()
    Dim dr as OledbDataReader
    Dim sSQL as String = "Select * from YourTable"

    cn = New OledbConnection("Provider=Microsoft.Jey.Oledb.4.0;Source=<path to your database>")
    cn.Open()
    with cmd
        .Connection = cn
        .CommandText = sSQL
        .CommandTimeout = 0
        dr = .ExecuteReader()
    end with
    do while dr.Read()
       ' get that values from each field in the current record
    Loop
    dr.Close()
    cn.Close()


    you ca put it either in the procedure or on a form level
    0
     
    LVL 1

    Author Comment

    by:newbie22
    Imports System.Data.Oledb

    imports is underlined with blue ?

    do i need to add any reference?
    0
     
    LVL 28

    Expert Comment

    by:iboutchkine
    Are you sure that you Imports System.Data.Oledb to the right place.
    It has to be on the top of the form ( the first line)

    And you don't ned any references
    0
     
    LVL 1

    Author Comment

    by:newbie22
    you were right I did everything u told me and now everything looks ok ,
    but when i click on button I get     this in green :   cn.Open()

    and error is :An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

    this is my code I plz look at it if u see any mistakes , i put everything under button event click ?
    I have tried same thing unter table1_load event.


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim cn As OleDbConnection
            Dim cmd As New OleDbCommand()
            Dim dr As OleDbDataReader
            Dim sSQL As String = "Select * from Table1"
            Dim b As Boolean

            cn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Source=c:\TEXTBOX.mdb")
            cn.Open()
            With cmd
                .Connection = cn
                .CommandText = sSQL
                .CommandTimeout = 0
                dr = .ExecuteReader()
            End With
            Do While dr.Read()
                ' get that values from each field in the current record
                If dr("1") = TextBox1.Text AndAlso dr("2") = TextBox2.Text Then
                    frm2.Show()
                    Exit Do

                End If

            Loop
            dr.Close()
            cn.Close()

        End Sub
    End Class
    0
     
    LVL 28

    Expert Comment

    by:iboutchkine
    try

    Dim cn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Source=c:\TEXTBOX.mdb")
            Dim cmd As New OleDbCommand()
            Dim dr As OleDbDataReader
            Dim sSQL As String = "Select * from Table1"
            Dim b As Boolean

    .......
    0
     
    LVL 1

    Author Comment

    by:newbie22
    again green
    0
     
    LVL 27

    Expert Comment

    by:planocz
    Yuo are making this a lot harder than it really is...
    Here is a sample code w/ ADO testing a ToolTip....

    'FORM1

    Public Class frmADOToolTip
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            InitializeData()
            PopulateListFromDS(DS)
        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents tipView As System.Windows.Forms.ToolTip
        Friend WithEvents lstBoxResults As System.Windows.Forms.ListBox
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container
            Me.lstBoxResults = New System.Windows.Forms.ListBox
            Me.tipView = New System.Windows.Forms.ToolTip(Me.components)
            Me.SuspendLayout()
            '
            'lstBoxResults
            '
            Me.lstBoxResults.Location = New System.Drawing.Point(28, 32)
            Me.lstBoxResults.Name = "lstBoxResults"
            Me.lstBoxResults.Size = New System.Drawing.Size(176, 160)
            Me.lstBoxResults.TabIndex = 0
            Me.tipView.SetToolTip(Me.lstBoxResults, "Click to test the tool tip")
            '
            'frmADOToolTip
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(236, 209)
            Me.Controls.Add(Me.lstBoxResults)
            Me.Name = "frmADOToolTip"
            Me.Text = "ADO ToolTip Test"
            Me.ResumeLayout(False)

        End Sub

    #End Region
        Private Sub InitializeData()

            Cursor.Current = Cursors.WaitCursor
            sDBName = "C:\Northwind.mdb"       '<---- A standard access database from Microsoft
            sTableName = "Products"

            OpenDBADOConnection()

            sSql = ""
            sSql = "SELECT * "
            sSql += "FROM " & sTableName & " "
            sSql += "ORDER BY ProductName"
            Try
                'TblAdapter = New SqlDataAdapter(sSql, Connect)            'FOR SQL Server
                'TblAdapter = New Odbc.OdbcDataAdapter(sSQL, SyConnect)    'FOR SyBase Server
                ADOAdapter = New OleDb.OleDbDataAdapter(sSql, Con)         'FOR ADO Access database
                ADOAdapter.Fill(DS)

            Catch Exp As Data.OleDb.OleDbException
                MsgBox("FillDataSet Procedure Error", MsgBoxStyle.Critical, "Load Report Error")
            Catch Exp As Exception
                MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
            End Try
            Cursor.Current = Cursors.Default
        End Sub
        Private Sub lstboxResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstBoxResults.Click
            Dim sCost As String
            Dim sUnits As String
            Dim str As String
            sCost = DS.Tables(0).Rows(sender.selectedindex)("Unitprice").ToString()
            sUnits = DS.Tables(0).Rows(sender.selectedindex)("UnitsInStock").ToString()
            str = "Cost: " & Format(CDbl(sCost), "$###.00") & vbCr & "Unit In Stock: " & sUnits

            tipView.SetToolTip(Me.lstBoxResults, str)
        End Sub
     
        Private Sub PopulateListFromDS(ByVal DS)
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            lstBoxResults.Items.Clear()

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the product name for each record.
                    s = DS.Tables(0).Rows(i)("ProductName").ToString()
                    ' Add product name to the list box
                    lstBoxResults.Items.Add(s)
                End If
            Next i
        End Sub
    End Class


    'MODULE CLASS

    Imports System.Data.SqlClient

    Module ModADO
    #Region " MY Global Vars "
        '********* database Var's ************
        Public sSql As String
        Public sTableName As String
        Public sColumns() As String
        Public sTables() As String
        Public catArch As ADOX.Catalog
        Public iCounter As Short
        Public myDataRow As DataRow
        Public DS As New DataSet
        Public TblAdapter As Odbc.OdbcDataAdapter   '(sSql or SyConnect)
        Public ADOAdapter As OleDb.OleDbDataAdapter '(ADO)

        '**** Server Connection Vars *********
        Public sDBServer As String               '<--- Server Name
        Public sUSERid As String                 '<--- User Id
        Public sDBName As String                 '<--- Database Name
        Public sDBPass As String                 '<--- Password
        Public Con As OleDb.OleDbConnection      '<--- for Access
        Public Connect As SqlConnection          '<--- for msSQL
        Public SyConnect As Odbc.OdbcConnection  '<---- for Sybase

        '******* Standard Var's *************
        Public sAppPath As String = Application.StartupPath

    #End Region
    #Region " MY Server Connections "
        Public Sub OpenDBSqlConnection()
            If Len(sDBPass) = 0 Then
                sDBPass = ""
            End If
            Try
                Connect = New SqlConnection("Initial Catalog=" & sDBName & ";Data Source=" & sDBServer & ";User ID=" & sUSERid & ";password=" & sDBPass & ";")
                Connect.Open()
                Connect.Close()
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
        Public Sub OpenDBADOConnection()
            Try
                Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBName & ";password=" & sDBPass & ";")
                Con.Open()
                Con.Close()
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
        Public Sub OpenDBSyBaseConnection()
            Try
                SyConnect = New Odbc.OdbcConnection("DSN=Recapture ASA 7;UID=dba;PWD=sql")
                SyConnect.Open()
                SyConnect.Close()
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
    #End Region
    End Module

    'THe MODULE has extra code in it that you can delete or use in later apps.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    THANKS for ur post. I managed to put that code with northwind mdb and it works.

    But to be honest I am lost I it.

    Don't know where to put my name of my user row and pass row.
    Then when i have changed path to my database I get this underlined in yellow :

    For i = 1 To DS.Tables(1).Rows.Count - 1     ------------ An unhandled exception of type 'System.IndexOutOfRangeException' occurred in microsoft.visualbasic.dll

    Additional information: Cannot find table 1.

    Sorry if u can help me 'cause I am lost
    0
     
    LVL 27

    Expert Comment

    by:planocz
    Why are you using Tables(1)? It should be 0.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    it is 0
    0
     
    LVL 1

    Author Comment

    by:newbie22
    I just tried with 1
    0
     
    LVL 1

    Author Comment

    by:newbie22

            Cursor.Current = Cursors.WaitCursor
            sDBName = "C:\TEXTBOX.mdb"       '<---- A standard access database from Microsoft
            sTableName = "User"  

    .. this is good I suposse?
    0
     
    LVL 27

    Expert Comment

    by:planocz
    I made a sample Login; I you want to use a MDI Form w/ your Login?

    Public Class frmLoginADO
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            InitializeData()
        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents lblName As System.Windows.Forms.Label
        Friend WithEvents lblPassword As System.Windows.Forms.Label
        Friend WithEvents txtName As System.Windows.Forms.TextBox
        Friend WithEvents txtPassword As System.Windows.Forms.TextBox
        Friend WithEvents btnOK As System.Windows.Forms.Button
        Friend WithEvents btnCancel As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.lblName = New System.Windows.Forms.Label
            Me.lblPassword = New System.Windows.Forms.Label
            Me.txtName = New System.Windows.Forms.TextBox
            Me.txtPassword = New System.Windows.Forms.TextBox
            Me.btnOK = New System.Windows.Forms.Button
            Me.btnCancel = New System.Windows.Forms.Button
            Me.SuspendLayout()
            '
            'lblName
            '
            Me.lblName.Location = New System.Drawing.Point(12, 16)
            Me.lblName.Name = "lblName"
            Me.lblName.Size = New System.Drawing.Size(84, 20)
            Me.lblName.TabIndex = 0
            Me.lblName.Text = "Login Name:"
            '
            'lblPassword
            '
            Me.lblPassword.Location = New System.Drawing.Point(8, 56)
            Me.lblPassword.Name = "lblPassword"
            Me.lblPassword.Size = New System.Drawing.Size(88, 20)
            Me.lblPassword.TabIndex = 1
            Me.lblPassword.Text = "Login Password:"
            '
            'txtName
            '
            Me.txtName.Location = New System.Drawing.Point(100, 16)
            Me.txtName.Name = "txtName"
            Me.txtName.Size = New System.Drawing.Size(160, 20)
            Me.txtName.TabIndex = 2
            Me.txtName.Text = ""
            '
            'txtPassword
            '
            Me.txtPassword.Location = New System.Drawing.Point(100, 56)
            Me.txtPassword.Name = "txtPassword"
            Me.txtPassword.Size = New System.Drawing.Size(160, 20)
            Me.txtPassword.TabIndex = 3
            Me.txtPassword.Text = ""
            '
            'btnOK
            '
            Me.btnOK.Location = New System.Drawing.Point(16, 92)
            Me.btnOK.Name = "btnOK"
            Me.btnOK.TabIndex = 4
            Me.btnOK.Text = "&Ok"
            '
            'btnCancel
            '
            Me.btnCancel.Location = New System.Drawing.Point(108, 92)
            Me.btnCancel.Name = "btnCancel"
            Me.btnCancel.TabIndex = 5
            Me.btnCancel.Text = "&Cancel"
            '
            'frmLoginADO
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 125)
            Me.Controls.Add(Me.btnCancel)
            Me.Controls.Add(Me.btnOK)
            Me.Controls.Add(Me.txtPassword)
            Me.Controls.Add(Me.txtName)
            Me.Controls.Add(Me.lblPassword)
            Me.Controls.Add(Me.lblName)
            Me.Name = "frmLoginADO"
            Me.Text = "frmLoginADO"
            Me.ResumeLayout(False)

        End Sub

    #End Region
        Private Sub InitializeData()

            Cursor.Current = Cursors.WaitCursor
            sDBName = "C:\Textbox.mdb"       '<---- A standard access database from Microsoft
            sTableName = "User"

            OpenDBADOConnection()

            sSql = ""
            sSql = "SELECT * "
            sSql += "FROM " & sTableName & " "
            sSql += "ORDER BY Name"
            Try
                'TblAdapter = New SqlDataAdapter(sSql, Connect)            'FOR SQL Server
                'TblAdapter = New Odbc.OdbcDataAdapter(sSQL, SyConnect)    'FOR SyBase Server
                ADOAdapter = New OleDb.OleDbDataAdapter(sSql, Con)         'FOR ADO Access database
                ADOAdapter.Fill(DS)

            Catch Exp As Data.OleDb.OleDbException
                MsgBox("FillDataSet Procedure Error", MsgBoxStyle.Critical, "Load Report Error")
            Catch Exp As Exception
                MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
            End Try
            Cursor.Current = Cursors.Default
        End Sub
        Private Function CheckNameFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("Name").ToString()  '<----Field name "Name"
                    ' Check Name in the Textbox
                    If txtName.Text = s Then
                        'Name was found
                        Return True
                    Else
                        Return False
                    End If
                End If
            Next i
        End Function
        Private Function CheckPasswordFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("Password").ToString()   '<----Field name "Paswword"
                    ' Check Name in the Textbox
                    If txtPassword.Text = s Then
                        'Name was found
                        Return True
                    Else
                        Return False
                    End If
                End If
            Next i
        End Function
        Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            If txtName.Text <> "" And txtPassword.Text <> "" Then
                If CheckNameFromDS(DS) = True Then
                    If CheckPasswordFromDS(DS) = True Then
                        'The Name and Password Are good
                        'Go do tsomething
                    Else
                        MessageBox.Show("Password not in Database")
                    End If
                End If
            Else
                MessageBox.Show("Name or Password is missing")
            End If
        End Sub

        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Me.Close()
        End Sub
    End Class
    0
     
    LVL 27

    Expert Comment

    by:planocz
    The code above needs some changes in....

       Private Function CheckNameFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("Name").ToString()  '<----Field name "Name"
                    ' Check Name in the Textbox
                    If UCase(txtName.Text) = UCase(s) Then
                        'Name was found
                        Return True              
                    End If
                End If
            Next i
        End Function
        Private Function CheckPasswordFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("Password").ToString()   '<----Field name "Password"
                    ' Check Name in the Textbox
                    If UCase(txtPassword.Text) = UCase(s) Then
                        'Name was found
                        Return True
                    End If
                End If
            Next i
        End Function

    This code is very basic and you will need to adjust it to fit your needs.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    THANKS A LOT FOR HELPING ME IN THIS TOPIC.

    I managed to set this code and adjust it for my dbase.
    But now i  only get form2 opened.

    Please if u can see my code once more i will post it here , It making me mad :).

    Just to inform you.  
    TEXTBOX.mdb  <---------- database
    Table1 <---- ---------------- table in database with 2 rows
    1  <----------------------------1 st row username
    2  <----------------------------2 nd row pass

    And when placed your last code many things were highlited , and I have used module from ur 1st post. (without it everything was blue). And I deleted some things from module 'cause they were blue too.

    here is the code :


    mports System.Data.SqlClient
    Public Class frmLoginADO
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            InitializeData()
        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents lblName As System.Windows.Forms.Label
        Friend WithEvents lblPassword As System.Windows.Forms.Label
        Friend WithEvents txtName As System.Windows.Forms.TextBox
        Friend WithEvents txtPassword As System.Windows.Forms.TextBox
        Friend WithEvents btnOK As System.Windows.Forms.Button
        Friend WithEvents btnCancel As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.lblName = New System.Windows.Forms.Label()
            Me.lblPassword = New System.Windows.Forms.Label()
            Me.txtName = New System.Windows.Forms.TextBox()
            Me.txtPassword = New System.Windows.Forms.TextBox()
            Me.btnOK = New System.Windows.Forms.Button()
            Me.btnCancel = New System.Windows.Forms.Button()
            Me.SuspendLayout()
            '
            'lblName
            '
            Me.lblName.Location = New System.Drawing.Point(12, 16)
            Me.lblName.Name = "lblName"
            Me.lblName.Size = New System.Drawing.Size(84, 20)
            Me.lblName.TabIndex = 0
            Me.lblName.Text = "Login Name:"
            '
            'lblPassword
            '
            Me.lblPassword.Location = New System.Drawing.Point(8, 56)
            Me.lblPassword.Name = "lblPassword"
            Me.lblPassword.Size = New System.Drawing.Size(88, 20)
            Me.lblPassword.TabIndex = 1
            Me.lblPassword.Text = "Login Password:"
            '
            'txtName
            '
            Me.txtName.Location = New System.Drawing.Point(100, 16)
            Me.txtName.Name = "txtName"
            Me.txtName.Size = New System.Drawing.Size(160, 20)
            Me.txtName.TabIndex = 2
            Me.txtName.Text = ""
            '
            'txtPassword
            '
            Me.txtPassword.Location = New System.Drawing.Point(100, 56)
            Me.txtPassword.Name = "txtPassword"
            Me.txtPassword.Size = New System.Drawing.Size(160, 20)
            Me.txtPassword.TabIndex = 3
            Me.txtPassword.Text = ""
            '
            'btnOK
            '
            Me.btnOK.Location = New System.Drawing.Point(16, 92)
            Me.btnOK.Name = "btnOK"
            Me.btnOK.TabIndex = 4
            Me.btnOK.Text = "&Ok"
            '
            'btnCancel
            '
            Me.btnCancel.Location = New System.Drawing.Point(108, 92)
            Me.btnCancel.Name = "btnCancel"
            Me.btnCancel.TabIndex = 5
            Me.btnCancel.Text = "&Cancel"
            '
            'frmLoginADO
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 125)
            Me.Controls.Add(Me.btnCancel)
            Me.Controls.Add(Me.btnOK)
            Me.Controls.Add(Me.txtPassword)
            Me.Controls.Add(Me.txtName)
            Me.Controls.Add(Me.lblPassword)
            Me.Controls.Add(Me.lblName)
            Me.Name = "frmLoginADO"
            Me.Text = "frmLoginADO"
            Me.ResumeLayout(False)

        End Sub

    #End Region
        Private Sub InitializeData()

            Cursor.Current = Cursors.WaitCursor
            sDBName = "C:\Textbox.mdb"       '<---- A standard access database from Microsoft
            sTableName = "Table1"

            OpenDBADOConnection()

            sSql = ""
            sSql = "SELECT * "
            sSql += "FROM " & sTableName & " "
            sSql += "ORDER BY Name"
            Try
                'TblAdapter = New SqlDataAdapter(sSql, Connect)            'FOR SQL Server
                'TblAdapter = New Odbc.OdbcDataAdapter(sSQL, SyConnect)    'FOR SyBase Server
                ADOAdapter = New OleDb.OleDbDataAdapter(sSql, Con)         'FOR ADO Access database
                ADOAdapter.Fill(DS)

            Catch Exp As Data.OleDb.OleDbException
                MsgBox("FillDataSet Procedure Error", MsgBoxStyle.Critical, "Load Report Error")
            Catch Exp As Exception
                MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
            End Try
            Cursor.Current = Cursors.Default
        End Sub
        Private Function CheckNameFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("1").ToString()  '<----Field name "Name"
                    ' Check Name in the Textbox
                    If UCase(txtName.Text) = UCase(s) Then
                        'Name was found
                        Return True
                    End If
                End If
            Next i
        End Function
        Private Function CheckPasswordFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("2").ToString()   '<----Field name "Password"
                    ' Check Name in the Textbox
                    If UCase(txtPassword.Text) = UCase(s) Then
                        'Name was found
                        Return True
                    End If
                End If
            Next i
        End Function

    End Class

    'MODULE CLASS



    Module ModADO
    #Region " MY Global Vars "
        '********* database Var's ************
        Public sSql As String
        Public sTableName As String
        Public sColumns() As String
        Public sTables() As String

        Public iCounter As Short
        Public myDataRow As DataRow
        Public DS As New DataSet()

        Public ADOAdapter As OleDb.OleDbDataAdapter '(ADO)

        '**** Server Connection Vars *********
        Public sDBServer As String               '<--- Server Name
        Public sUSERid As String                 '<--- User Id
        Public sDBName As String                 '<--- Database Name
        Public sDBPass As String                 '<--- Password
        Public Con As OleDb.OleDbConnection      '<--- for Access
       

        '******* Standard Var's *************
        Public sAppPath As String = Application.StartupPath

    #End Region
    #Region " MY Server Connections "
        Public Sub OpenDBSqlConnection()
            If Len(sDBPass) = 0 Then
                sDBPass = ""
            End If
            Try

               
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
        Public Sub OpenDBADOConnection()
            Try
                Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBName & ";password=" & sDBPass & ";")
                Con.Open()
                Con.Close()
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
        Public Sub OpenDBSyBaseConnection()
            Try

               
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
    #End Region
    End Module

    'THe MODULE has extra code in it that you can delete or use in later apps.

    0
     
    LVL 27

    Expert Comment

    by:planocz
    Do you want to use a MDI Form w/ your Login?

    MDI form is the parent form
    and form2 is a child form.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    yes 1 st form (parent) will be 1st thing user will se when he open .exe file
    0
     
    LVL 27

    Expert Comment

    by:planocz
    change form2 name to be  frmMain
    then in the properties box change IsMDIContainer = false  to True

    If form1 is or login form it is best to rename it to frmLogin

    Then add this to your frmMain form...

       <STAThread()> Shared Sub Main()
            Dim objForm As New frmLogin
            objForm.ShowDialog()
            If bLogin = True Then
                System.Windows.Forms.Application.Run(New frmMainForm)
            End If
        End Sub


    Add this gloabl var to the module form

    Public bLogin as Boolean

    and back in your frmLogin form add this to your OK button

        Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            If txtName.Text <> "" And txtPassword.Text <> "" Then
                If CheckNameFromDS(DS) = True Then
                    If CheckPasswordFromDS(DS) = True Then
                        bLogin = True                                                '<------ADD THIS
                    Else
                        MessageBox.Show("Password not in Database")
                    End If
                End If
            Else
                MessageBox.Show("Name or Password is missing")
            End If
        End Sub
    0
     
    LVL 1

    Author Comment

    by:newbie22
    nope n frmain bLogin is blue and this frmMainForm.

    dunno I am stupid or what but I can't get it  work!!!!!
    There must be some mistake I made but i don't know where. myb in module or somewhere but it doesn't work.

    Thank you planocz for ur patience you r real m8.
    0
     
    LVL 27

    Expert Comment

    by:planocz
    The best thing to do is go to this statement on your question
    And copy this code into a new app. and not try to paste into your old code.
    Then try and troubleshoot any problems.

    Comment from planocz
    Date: 11/03/2004 06:36AM PST
     Comment  


    I made a sample Login; I you want to use a MDI Form w/ your Login?
     
    0
     
    LVL 1

    Author Comment

    by:newbie22
    I tried but I need to add module to that one u wrote me.
    And when I add module some things in module r underlined , so when I delete them everything looks fine but it doesn't work

    Ok I will try once again and then repost.
    0
     
    LVL 27

    Expert Comment

    by:planocz
    When you have red underlines it is from a item not being reference.

    do you have ADOB in your reference list?

    right click on the reference name and add reference
    when window pops up click on com tab and add the ADOB.dll file (Microsoft ActiveX Data Objects 2.8 Library) <--this is what I use.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    I added ecerything like u told me.
    and microsoft activex data..
    and module and everything and pasted it to a whole no project.

    Now I will paste code and errors.
    Thx

    CODE:


    'FORM1

    Imports System.Data.SqlClient

    Public Class frmLogin
        Inherits System.Windows.Forms.Form

        Public bLogin As Boolean
    #Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            InitializeData()
        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents lblName As System.Windows.Forms.Label
        Friend WithEvents lblPassword As System.Windows.Forms.Label
        Friend WithEvents txtName As System.Windows.Forms.TextBox
        Friend WithEvents txtPassword As System.Windows.Forms.TextBox
        Friend WithEvents btnOK As System.Windows.Forms.Button
        Friend WithEvents btnCancel As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.lblName = New System.Windows.Forms.Label()
            Me.lblPassword = New System.Windows.Forms.Label()
            Me.txtName = New System.Windows.Forms.TextBox()
            Me.txtPassword = New System.Windows.Forms.TextBox()
            Me.btnOK = New System.Windows.Forms.Button()
            Me.btnCancel = New System.Windows.Forms.Button()
            Me.SuspendLayout()
            '
            'lblName
            '
            Me.lblName.Location = New System.Drawing.Point(12, 16)
            Me.lblName.Name = "lblName"
            Me.lblName.Size = New System.Drawing.Size(84, 20)
            Me.lblName.TabIndex = 0
            Me.lblName.Text = "Login Name:"
            '
            'lblPassword
            '
            Me.lblPassword.Location = New System.Drawing.Point(8, 56)
            Me.lblPassword.Name = "lblPassword"
            Me.lblPassword.Size = New System.Drawing.Size(88, 20)
            Me.lblPassword.TabIndex = 1
            Me.lblPassword.Text = "Login Password:"
            '
            'txtName
            '
            Me.txtName.Location = New System.Drawing.Point(100, 16)
            Me.txtName.Name = "txtName"
            Me.txtName.Size = New System.Drawing.Size(160, 20)
            Me.txtName.TabIndex = 2
            Me.txtName.Text = ""
            '
            'txtPassword
            '
            Me.txtPassword.Location = New System.Drawing.Point(100, 56)
            Me.txtPassword.Name = "txtPassword"
            Me.txtPassword.Size = New System.Drawing.Size(160, 20)
            Me.txtPassword.TabIndex = 3
            Me.txtPassword.Text = ""
            '
            'btnOK
            '
            Me.btnOK.Location = New System.Drawing.Point(16, 92)
            Me.btnOK.Name = "btnOK"
            Me.btnOK.TabIndex = 4
            Me.btnOK.Text = "&Ok"
            '
            'btnCancel
            '
            Me.btnCancel.Location = New System.Drawing.Point(108, 92)
            Me.btnCancel.Name = "btnCancel"
            Me.btnCancel.TabIndex = 5
            Me.btnCancel.Text = "&Cancel"
            '
            'frmLoginADO
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 125)
            Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK, Me.txtPassword, Me.txtName, Me.lblPassword, Me.lblName})
            Me.Name = "frmLoginADO"
            Me.Text = "frmLogin"
            Me.ResumeLayout(False)

        End Sub

    #End Region
        Private Sub InitializeData()

            Cursor.Current = Cursors.WaitCursor
            sDBName = "C:\TEXTBOX.mdb"       '<---- A standard access database from Microsoft
            sTableName = "Table1"

            OpenDBADOConnection()

            sSql = ""
            sSql = "SELECT * "
            sSql += "FROM " & sTableName & " "
            sSql += "ORDER BY Name"
            Try
                'TblAdapter = New SqlDataAdapter(sSql, Connect)            'FOR SQL Server
                'TblAdapter = New Odbc.OdbcDataAdapter(sSQL, SyConnect)    'FOR SyBase Server
                ADOAdapter = New OleDb.OleDbDataAdapter(sSql, Con)         'FOR ADO Access database
                ADOAdapter.Fill(DS)

            Catch Exp As Data.OleDb.OleDbException
                MsgBox("FillDataSet Procedure Error", MsgBoxStyle.Critical, "Load Report Error")
            Catch Exp As Exception
                MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
            End Try
            Cursor.Current = Cursors.Default
        End Sub
        Private Function CheckNameFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("1").ToString()  '<----Field name "Name"
                    ' Check Name in the Textbox
                    If UCase(txtName.Text) = UCase(s) Then
                        'Name was found
                        Return True
                    End If
                End If
            Next i
        End Function
        Private Function CheckPasswordFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("2").ToString()   '<----Field name "Password"
                    ' Check Name in the Textbox
                    If UCase(txtPassword.Text) = UCase(s) Then
                        'Name was found
                        Return True
                    End If
                End If
            Next i
        End Function

        Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            If txtName.Text <> "" And txtPassword.Text <> "" Then
                If CheckNameFromDS(DS) = True Then
                    If CheckPasswordFromDS(DS) = True Then
                        bLogin = True
                        'The Name and Password Are good
                        'Go do tsomething
                    Else
                        MessageBox.Show("Password not in Database")
                    End If
                End If
            Else
                MessageBox.Show("Name or Password is missing")
            End If
        End Sub

        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Me.Close()
        End Sub

        Private Sub frmLoginADO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        End Sub
    End Class

    'MODULE CLASS



    Module ModADO
    #Region " MY Global Vars "

        '********* database Var's ************
        Public sSql As String
        Public sTableName As String
        Public sColumns() As String
        Public sTables() As String
        Public catArch As ADOX.Catalog
        Public iCounter As Short
        Public myDataRow As DataRow
        Public DS As New DataSet()
        Public TblAdapter As Odbc.OdbcDataAdapter   '(sSql or SyConnect)
        Public ADOAdapter As OleDb.OleDbDataAdapter '(ADO)
        Public bLogin As Boolean
        '**** Server Connection Vars *********
        Public sDBServer As String               '<--- Server Name
        Public sUSERid As String                 '<--- User Id
        Public sDBName As String                 '<--- Database Name
        Public sDBPass As String                 '<--- Password
        Public Con As OleDb.OleDbConnection      '<--- for Access
        Public Connect As SqlConnection          '<--- for msSQL
        Public SyConnect As Odbc.OdbcConnection  '<---- for Sybase

        '******* Standard Var's *************
        Public sAppPath As String = Application.StartupPath

    #End Region
    #Region " MY Server Connections "
        Public Sub OpenDBSqlConnection()
            If Len(sDBPass) = 0 Then
                sDBPass = ""
            End If
            Try
                Connect = New SqlConnection("Initial Catalog=" & sDBName & ";Data Source=" & sDBServer & ";User ID=" & sUSERid & ";password=" & sDBPass & ";")
                Connect.Open()
                Connect.Close()
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
        Public Sub OpenDBADOConnection()
            Try
                Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBName & ";password=" & sDBPass & ";")
                Con.Open()
                Con.Close()
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
        Public Sub OpenDBSyBaseConnection()
            Try
                SyConnect = New Odbc.OdbcConnection("DSN=Recapture ASA 7;UID=dba;PWD=sql")
                SyConnect.Open()
                SyConnect.Close()
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
    #End Region
    End Module

    'THe MODULE has extra code in it that you can delete or use in later apps.


    'FORM 2 ------------ IsMDIContainer =  True

    Public Class frmMain
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call

        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            '
            'frMain
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 266)
            Me.IsMdiContainer = True
            Me.Name = "frMain"
            Me.Text = "frMain"

        End Sub

    #End Region


    <STAThread()> Shared Sub Main()
            Dim objForm As New frmLogin()
            objForm.ShowDialog()
            If bLogin = True Then
                System.Windows.Forms.Application.Run(New frmMainForm())
            End If
        End Sub


    End Class




    ERRORS:

    ...Visual Studio Projects\PASSWORD\Form1.vb(217): Type 'ADOX.Catalog' is not defined.

    ...\Visual Studio Projects\PASSWORD\Form1.vb(221): Type 'Odbc.OdbcDataAdapter' is not defined.

    ...\Visual Studio Projects\PASSWORD\Form1.vb(231): Type 'Odbc.OdbcConnection' is not defined.

    ...\Visual Studio Projects\PASSWORD\Form1.vb(263): Type 'Odbc.OdbcConnection' is not defined.

    ...\Visual Studio Projects\PASSWORD\Form2.vb(51): Type 'frmMainForm' is not defined.

    'Sub Main' was not found in 'PASSWORD.Form1'.


    THX








    0
     
    LVL 27

    Expert Comment

    by:planocz
    add this to the top of your module

    Imports ADODB
    Imports System.Data.SqlClient

    and remove this in module

    Public catArch As ADOX.Catalog


    Check the names of your .vb files to match with new form names

    Example: form2.vb is now frmMainForm.vb
    0
     
    LVL 1

    Author Comment

    by:newbie22
    \Visual Studio Projects\PASSWORD\Form1.vb(232): Type 'Odbc.OdbcConnection' is not defined.

    \Visual Studio Projects\PASSWORD\Form1.vb(264): Type 'Odbc.OdbcConnection' is not defined.

    'Sub Main' was not found in 'PASSWORD.Form1'.


    I have renamed form1----frmMainForm
    and form 2-----------------frmLogin
    0
     
    LVL 27

    Expert Comment

    by:planocz
    'Sub Main' was not found in 'PASSWORD.Form1'.

    goto project on your menu
    goto bottom click on properties
    then look at the dropdown list on the Startup object:
    pick frmMainForm as your startup form.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    \Visual Studio Projects\PASSWORD\frmLogin.vb(222): Type 'Odbc.OdbcDataAdapter' is not defined.

    \Visual Studio Projects\PASSWORD\frmLogin.vb(232): Type 'Odbc.OdbcConnection' is not defined.

    \Visual Studio Projects\PASSWORD\frmLogin.vb(264): Type 'Odbc.OdbcConnection' is not defined.

    'Sub Main' was not found in 'PASSWORD.Form1'.

    ok form1 with user and pass is  frmLogin
        form2 is frmMain

    and frmlogin is 1st form
    then is frmmain
    and then ModADO
    0
     
    LVL 27

    Accepted Solution

    by:
    OK lets try it again.

    This is the only code at this point, that is on the MAINFORM.
    also in the properties box change IsMDIContainer = false  to True


    Public Class frmMainForm
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call

        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            '
            'frmMainForm
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 273)
            Me.IsMdiContainer = True
            Me.Name = "frmMainForm"
            Me.Text = "frmMainForm"

        End Sub

    #End Region
        'Run the application
        'The main entry point for the application
        <STAThread()> Shared Sub Main()
            Dim objForm As New frmLogin
            objForm.ShowDialog()
            If bLogin = True Then
                System.Windows.Forms.Application.Run(New frmMainForm)
            End If
        End Sub
    End Class
    0
     
    LVL 27

    Expert Comment

    by:planocz
    Next this is the only code that the frmLogin should have....

    Public Class frmLogin
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            InitializeData()
        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents lblName As System.Windows.Forms.Label
        Friend WithEvents lblPassword As System.Windows.Forms.Label
        Friend WithEvents txtName As System.Windows.Forms.TextBox
        Friend WithEvents txtPassword As System.Windows.Forms.TextBox
        Friend WithEvents btnOK As System.Windows.Forms.Button
        Friend WithEvents btnCancel As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.lblName = New System.Windows.Forms.Label
            Me.lblPassword = New System.Windows.Forms.Label
            Me.txtName = New System.Windows.Forms.TextBox
            Me.txtPassword = New System.Windows.Forms.TextBox
            Me.btnOK = New System.Windows.Forms.Button
            Me.btnCancel = New System.Windows.Forms.Button
            Me.SuspendLayout()
            '
            'lblName
            '
            Me.lblName.Location = New System.Drawing.Point(12, 16)
            Me.lblName.Name = "lblName"
            Me.lblName.Size = New System.Drawing.Size(84, 20)
            Me.lblName.TabIndex = 0
            Me.lblName.Text = "Login Name:"
            '
            'lblPassword
            '
            Me.lblPassword.Location = New System.Drawing.Point(8, 56)
            Me.lblPassword.Name = "lblPassword"
            Me.lblPassword.Size = New System.Drawing.Size(88, 20)
            Me.lblPassword.TabIndex = 1
            Me.lblPassword.Text = "Login Password:"
            '
            'txtName
            '
            Me.txtName.Location = New System.Drawing.Point(100, 16)
            Me.txtName.Name = "txtName"
            Me.txtName.Size = New System.Drawing.Size(160, 20)
            Me.txtName.TabIndex = 2
            Me.txtName.Text = ""
            '
            'txtPassword
            '
            Me.txtPassword.Location = New System.Drawing.Point(100, 56)
            Me.txtPassword.Name = "txtPassword"
            Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
            Me.txtPassword.Size = New System.Drawing.Size(160, 20)
            Me.txtPassword.TabIndex = 3
            Me.txtPassword.Text = ""
            '
            'btnOK
            '
            Me.btnOK.Location = New System.Drawing.Point(16, 92)
            Me.btnOK.Name = "btnOK"
            Me.btnOK.TabIndex = 4
            Me.btnOK.Text = "&Ok"
            '
            'btnCancel
            '
            Me.btnCancel.Location = New System.Drawing.Point(108, 92)
            Me.btnCancel.Name = "btnCancel"
            Me.btnCancel.TabIndex = 5
            Me.btnCancel.Text = "&Cancel"
            '
            'frmLoginADO
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(292, 125)
            Me.Controls.Add(Me.btnCancel)
            Me.Controls.Add(Me.btnOK)
            Me.Controls.Add(Me.txtPassword)
            Me.Controls.Add(Me.txtName)
            Me.Controls.Add(Me.lblPassword)
            Me.Controls.Add(Me.lblName)
            Me.Name = "frmLogin"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "frmLogin"
            Me.ResumeLayout(False)

        End Sub

    #End Region
        Private Sub InitializeData()

            Cursor.Current = Cursors.WaitCursor
            sDBName = "C:\Textbox.mdb"       '<---- A standard access database from Microsoft
            sTableName = "User"

            OpenDBADOConnection()

            sSql = ""
            sSql = "SELECT * "
            sSql += "FROM " & sTableName & " "
            sSql += "ORDER BY Name"
            Try
                'TblAdapter = New SqlDataAdapter(sSql, Connect)            'FOR SQL Server
                'TblAdapter = New Odbc.OdbcDataAdapter(sSQL, SyConnect)    'FOR SyBase Server
                ADOAdapter = New OleDb.OleDbDataAdapter(sSql, Con)         'FOR ADO Access database
                ADOAdapter.Fill(DS)

            Catch Exp As Data.OleDb.OleDbException
                MsgBox("FillDataSet Procedure Error", MsgBoxStyle.Critical, "Load Report Error")
            Catch Exp As Exception
                MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
            End Try
            Cursor.Current = Cursors.Default
        End Sub
        Private Function CheckNameFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("Name").ToString()  '<----Field name "Name"
                    ' Check Name in the Textbox
                    If UCase(txtName.Text) = UCase(s) Then
                        'Name was found
                        Return True              
                    End If
                End If
            Next i
        End Function
        Private Function CheckPasswordFromDS(ByVal DS) As Boolean
            ' A table in a dataset is used to populate a list box with
            ' product name from the products table.
            ' With the dataset the name of the table and field must be known
            ' at design time. If they are misspelled or mistyped
            ' an error will be generated only at runtime.

            Dim s As String
            Dim i As Integer

            For i = 0 To DS.Tables(0).Rows.Count - 1
                ' Check to see if row is flagged as deleted.
                If Not DS.Tables(0).Rows(i).RowState = DataRowState.Deleted Then
                    ' Get the name for each record.
                    s = DS.Tables(0).Rows(i)("Password").ToString()   '<----Field name "Password"
                    ' Check Name in the Textbox
                    If UCase(txtPassword.Text) = UCase(s) Then
                        'Name was found
                        Return True
                    End If
                End If
            Next i
        End Function
        Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            If txtName.Text <> "" And txtPassword.Text <> "" Then
                If CheckNameFromDS(DS) = True Then
                    If CheckPasswordFromDS(DS) = True Then
                        bLogin = True
                        MessageBox.Show("You are IN")
                        Me.Close()
                    Else
                        MessageBox.Show("Password not in Database")
                    End If
                End If
            Else
                MessageBox.Show("Name or Password is missing")
            End If
        End Sub

        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            bLogin = False
            Me.Close()
        End Sub
     End Class
    0
     
    LVL 27

    Expert Comment

    by:planocz
    AND last in the Module you should only have this....

    Imports ADODB
    Imports System.Data.SqlClient
    Module ModADO
    #Region " MY Global Vars "
        '********* database Var's ************
        Public sSql As String
        Public sTableName As String
        Public myDataRow As DataRow
        Public DS As New DataSet
        Public ADOAdapter As OleDb.OleDbDataAdapter '(ADO)

        '**** Server Connection Vars *********
        Public sDBName As String                 '<--- Database Name
        Public sDBPass As String                 '<--- Password
        Public Con As OleDb.OleDbConnection      '<--- for Access

        '******* Standard Var's *************
        Public sAppPath As String = Application.StartupPath
        Public bLogin As Boolean
    #End Region
    #Region " MY Server Connections "
     
        Public Sub OpenDBADOConnection()
            Try
                Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBName & ";password=" & sDBPass & ";")
                Con.Open()
                Con.Close()
            Catch Ex As Exception
                MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
                Cursor.Current = Cursors.Default
            End Try
        End Sub
    #End Region
    End Module
    0
     
    LVL 1

    Author Comment

    by:newbie22
    THX almost there.

    1st everything is ok no more errors.  :)

    When I start I get small window named report error : FillDataSet Procedure error ,

    then I click ok and I get my frmLogin !!!!!!!!!!! It works perfect

    but when I enter correct user and pass and click ok I get this error in code:

    An unhandled exception of type 'System.IndexOutOfRangeException' occurred in microsoft.visualbasic.dll

    Additional information: Cannot find table 0

    and this is stroke in yellow : For i = 0 To DS.Tables(0).Rows.Count - 1
    0
     
    LVL 27

    Expert Comment

    by:planocz
    This is because the dataset did not get filled.
    Check for database name, pathes, etc.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    names are on 4 places and all are correct:

    sDBName = "C:\TEXTBOX.mdb"       '<---- my database
            sTableName = "Table1"           '<---- table1

     s = DS.Tables(0).Rows(i)("1").ToString()  '<----Field name "1" -- for username
    .
    .
    .
    s = DS.Tables(0).Rows(i)("2").ToString()   '<----Field name "2" -- fro password

    And that are all thing I needed to change. ( I hope so)
    0
     
    LVL 27

    Expert Comment

    by:planocz
    You can not use 1 and 2 for string names

    they need to be  names like User, Password
    0
     
    LVL 1

    Author Comment

    by:newbie22
    USER
    PASS

    again same thing
    0
     
    LVL 27

    Expert Comment

    by:planocz
    Do you change it in your database table too?
    0
     
    LVL 1

    Author Comment

    by:newbie22
    yes 1 row USER
    2nd PASS
    0
     
    LVL 27

    Expert Comment

    by:planocz
    row?
    DS.Tables(0).Rows(i)("USER").ToString()  '<----Field name
    DS.Tables(0).Rows(i)("PASS").ToString()  '<----Field name

    in your textbox.mdb, table1   the first column  is USER
    in your textbox.mdb, table1   the Second column  is PASS

    If this is right, then it should work.
    It works at my end, so I do not know anywhere else for you to look.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    TEXTBOX.mdb

    Table1

    USER   '        PASS
    ------------------------
     me     '       me
      you    '      you
               '


    It is like this , and that form is comunictaing with dbase 'cause I cant click ok when pass or user is inncorect , but when I put correct combination I get tha error
    0
     
    LVL 27

    Expert Comment

    by:planocz
    you would need to use break points and step thru the code.

    I have to leave now, be back tomorrow.
    0
     
    LVL 1

    Author Comment

    by:newbie22
    Thanks you have really deserved this points.

    C u 2morrow. :)
    0
     
    LVL 1

    Author Comment

    by:newbie22
    nothing yet.

    Same problem. :(

    I will give you pts now.

    If u ever find where the problem is plz post it here.
    YOu helped me much.

    Thx
    0
     
    LVL 27

    Expert Comment

    by:planocz
    This should not make a differents but try and
    change these two lines by replacing the field names with the index numbers of the database.

    s = DS.Tables(0).Rows(i)("1").ToString()  '<----Field name "1" -- for username
    s = DS.Tables(0).Rows(i)("2").ToString()   '<----Field name "2" -- fro password

    TO

    s = DS.Tables(0).Rows(i)(0).ToString()  '<----Field name "User" -- for username
    s = DS.Tables(0).Rows(i)(1).ToString()   '<----Field name "Pass" -- fro password
    0
     
    LVL 1

    Author Comment

    by:newbie22
    nope ( I have changed names in textbox.mdb  too)
    0
     
    LVL 27

    Expert Comment

    by:planocz
    This is what I have for the Database

    DataBase name ----- TexBox.mdb

    Table name -----  Table1

        Field Name                    Data Type
    ----------------------------------------------------
     User                                  Text                            <---- Which is Column 0
     Pass                                  Text<---- Which is Column 0

    0
     
    LVL 27

    Expert Comment

    by:planocz
    Error...
    Pass                                  Text                 <---- Which is Column 1

    0
     
    LVL 27

    Expert Comment

    by:planocz
    this is my SQl statement that I was using...
     
             sSql = ""
            sSql = "SELECT * "
            sSql += "FROM " & sTableName & " "
            sSql += "ORDER BY Name"                            '<----- If you are using User as Name then change this

    to read

    sSql += "ORDER BY User"
    0
     
    LVL 1

    Author Comment

    by:newbie22
    If u have a little time plz :  http://83.131.4.85/
    0
     
    LVL 1

    Author Comment

    by:newbie22
    it works NOWWWWWWWWWWWW.

    0
     
    LVL 27

    Expert Comment

    by:planocz

    Remove the quotes from ...."0" and "1"

    s = DS.Tables(0).Rows(i)("0").ToString()  '<----Field name "0" -- for username
    s = DS.Tables(0).Rows(i)("1").ToString()   '<----Field name "1" -- fro password

    Change to

    s = DS.Tables(0).Rows(i)(0).ToString()  '<----Field name "0" -- for username
    s = DS.Tables(0).Rows(i)(1).ToString()   '<----Field name "1" -- fro password


    Change SQL Statement  Name to User

    and

    goto your menu and click on project, Add new item,
    add a Module Class

    Move  your  mod class code into the new Module class from your frmLogin form
    0
     
    LVL 1

    Author Comment

    by:newbie22
     sSql += "ORDER BY Name"                            '<----- If you are using User as Name then change this

    to read

    sSql += "ORDER BY User"

    I tried to change name to "0" like in my mdb and it didn't work , but then I said to myself let me try once more without numbers , and I renamed it to user and pass and I have changed this line above to "user"  and   '<----- ----------MIRACLE--------- IT WORKS
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: From Zero to Hero with Nodejs & MongoDB

    Interested in Node.js, but don't know where to start or how to learn it properly? Confused about how the MEAN stack pieces of MongoDB, Expressjs, Angularjs, and Nodejs fit together? Or how it's even possible to run JavaScript outside of the browser?

    Suggested Solutions

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    931 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now