Q:

one time Login process

I have 2 forms in my winform application.Form 1 serves as a LogIn form and Form 2 serves as a page that a user would see after log in.Now my form 1 has two text boxes(for username and password) and a button(to login/show form 2).Every time a user runs the application, he has to login using form 1.What i want is, when a user logs in for once,from the next time on,he wouldn't have to log in anymore/he would see the form 2 directly instead of Form 1>Form 2. My code is :
Private Sub Login_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If My.Settings.UserName = "" Then
        Me.Show()
    Else
        Try
            provider = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source="
            dataFile = "XXXXXXX"
            connString = provider & dataFile
            myConnection.ConnectionString = connString

            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Login] WHERE [user_name] = @username AND [password] = @password", myConnection)

            myConnection.Open()
            cmd.Parameters.Add("@username", OleDbType.VarChar).Value = My.Settings.UserName
            cmd.Parameters.Add("@password", OleDbType.VarChar).Value = My.Settings.Password1
            Dim adapter As New OleDbDataAdapter(cmd)
            Dim table As New DataTable
            adapter.Fill(table)
            If table.Rows.Count <= 0 Then
                MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
            Else

                Form1.Show()
                Me.Close()
                myConnection.Close()

            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    My.Settings.UserName = user_name.Text
    My.Settings.Password1 = password.Text
    My.Settings.Save()
    provider = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source="
    dataFile = "D:\jyothi school\School Management\School Management\AddStudent.accdb"
    connString = provider & dataFile
    myConnection.ConnectionString = connString
    myConnection.Open()

    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Login] WHERE [user_name] = '" & My.Settings.UserName & "' AND [password] = '" & My.Settings.Password1 & "'", myConnection)
    Dim dr As OleDbDataReader = cmd.ExecuteReader
    If dr.HasRows Then
        Form1.Show()
        Me.Close()

    Else
        Me.Show()
        'MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
    End If
    myConnection.Close()

End Sub

Basically, i want the textboxes's values to be saved some where and then the application would use it to log in instead of making the user log in every time!

A:

First , create 2 settings object named Username and Password.Now on form 1's login button click, add these codes :
    my.settings.username=username.text
    My.settings.password=password.text
    My.Settings.Save

I suggest you to create a splash screen. Now add a background worker. Code for backgroundworker :
  If My.Settings.Username = ""  Then
  LogIn.Show

  Else

  Try
    Dim cmd as new oledbcommand("Select * rom [table] where [user_name]=@username and password=@password",connectionstring)

    con.Open()
        cmd.Parameters.Add("@username", OleDbType.VarChar).Value = my.settings.username
        cmd.Parameters.Add("@password", OleDbType.VarChar).Value = my.settings.password
        Dim adapter As New SqlDataAdapter(cmd)
        Dim table As New DataTable
        adapter.Fill(table)
        if table.rows.count <=0 then
         SHow warning message

        Else

         Form2.Show

        con.close

     Catch ex as exception
     Msgbox(ex.message)
     End try

