How to Create Login Form using vb.net and SqlServer Database
Imports System.Data.SqlClient library has a variety of classes and methods The classes we used to build log in form will be demonstrated which are : - Sqlconnection - Sqlcommand - sqldatareader
Sqlconnection Class Represents an open connection to a SQL Server database. This class cannot be inherited. Objects Properties Class name Sqlconnection Connectionstring() open() Con
Open () Connectionstring() Gets or sets the string used to open a SQL Server database. Open () Opens a database connection with the property settings specified by the Connectionstring
Sqlcommand Class Represents a Transact-SQL statement or stored procedure to execute against a SQL Server database. This class cannot be inherited. Objects Properties Class name sqlcommand Connection() Excutereader() Commandtext() Cmd
Commandtext() CONNECTION() Gets or sets the Transact-SQL statement, table name or stored procedure to execute at the data source. CONNECTION() Gets or sets the SqlConnection used by this instance of the SqlCommand
ExecuteReader() Sqlcommand Method that Sends the CommandText to the Connection and builds a SqlDataReader. Retrieving data using a DataReader involves creating an instance of the Command object and then creating a DataReader by calling Command.ExecuteReader to retrieve rows from a data source.
Sqldatareader Class Provides a way of reading a forward-only stream of rows from a SQL Server database. This class cannot be inherited. Objects Properties Class name Sqldatareader hasrows() rd
Hasrows() Gets a value that indicate whether that sqldatareader contains one or more rows .
Imports System.Data.SqlClient Dim con As New SqlConnection Dim cmd As New SqlCommand Dim rd As SqlDataReader con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\FitNation.mdf;Integrated Security=True;User Instance=True" cmd.Connection = con con.Open() cmd.CommandText = "select Username,Password from Trianer where Username = '" & TextBox1.Text & "' and Password= '" & TextBox2.Text & "'" rd = cmd.ExecuteReader If rd.HasRows Then Form4.Show() Else MsgBox("invalid username,password") End If
THE END