login_with_sqlserverx

Download Report

Transcript login_with_sqlserverx

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.
Class name
Properties
Objects
Sqlconnection
Connectionst
ring()
open()
Con
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.
Class name
Properties
Objects
sqlcommand
Connectio
n()
Excuteread
er()
Cmd
Commandte
xt()
COMMANDTEXT()
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.
Class
name
Properties
Objects
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 