Selasa, 18 Februari 2014

Creating basic login connected to database

Step 1 >>>> Create new windows form. Inside your form add two Label two TextBox and two Button. See image below for your reference. (fig. 1.0)

Figure 1.0















- click into your login form
- go into its property on the right side of your windows, change the FormBorderStyle to “FixedDialog

                        - change Minimize and Maximize value to “False” see image below. (fig. 1.1)

Figure 1.1














Step 2 >>>> double click into your form and add the following code on top of your form.

Imports MySql.Data
Imports MySql.Data.MySqlClient

Inside your Private Sub login_Load, add the code “SQLcon()”.

Step 3 >>>> double click into you OK button and paste this code;

Dim user As String = Nothing
        Dim pword As String = Nothing

        str = "select * from user where username = " & TextBox1.Text & " and password = " & TextBox2.Text & ""
        con.Open()
        cmd = New MySqlCommand(str, con)
        dr = cmd.ExecuteReader()


        Do While dr.Read()
            user = (dr.Item(0).ToString())
            pword = (dr.Item(1).ToString())
        Loop
        con.Close()
        cmd.Dispose()
        dr.Close()

        If user = TextBox1.Text And pword = TextBox2.Text Then
            MsgBox("login success")
        Else
            MsgBox("login failed")
        End If

try to run your program if it work properly.

0 komentar to “Creating basic login connected to database”

Posting Komentar

 

Internet Android App Copyright © 2016 -- Powered by Blogger