
SQL Connection, Command, and Data Reader Classes in .NET
Explore the essential classes like SqlConnection, SqlCommand, and SqlDataReader for building a login form in .NET. SqlConnection represents an open connection to a SQL Server database, SqlCommand is used for executing T-SQL statements, and SqlDataReader provides a way to read rows from a SQL Server database efficiently.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Imports Imports System. methods methods The classes we used to build log in form will be demonstrated The classes we used to build log in form will be demonstrated which are : - - Sqlconnection Sqlconnection - - Sqlcommand Sqlcommand - - sqldatareader sqldatareader System.Data. Data.SqlClient SqlClient library has a variety of classes and library has a variety of classes and which are :
SQLCONNECTION CLASS REPRESENTS AN OPEN CONNECTION TO A SQL SERVER DATABASE. THIS CLASS CANNOT BE INHERITED. Class name Sqlconnection Sqlconnection Connectionstr Connectionstr ing ing() () Properties open() open() Objects Con Con
CONNECTIONSTRING() Gets Gets or sets the string used to open a SQL Server or sets the string used to open a SQL Server database database. . Open () Open () Opens a database connection with the property Opens a database connection with the property settings specified by the settings specified by the Connectionstring 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 sqlcommand sqlcommand Connectio Connectio n() n() Excutereade Excutereade r r() () Commandtex Commandtex t t() () Properties Objects Cmd Cmd
COMMANDTEXT() Gets or sets the Transact-SQL statement, table name or stored procedure to execute at the data source. CONNECTION() CONNECTION() Gets or sets the SqlConnection used by this instance of the SqlCommand
EXECUTEREADER() Sqlcommand Sqlcommand Method that Sends the Method that Sends the CommandText the the Connection Connection and builds a and builds a SqlDataReader Retrieving data using a DataReader DataReader involves creating an instance of the Command Command object and then creating a DataReader calling Command. Command.ExecuteReader ExecuteReader to retrieve rows from a data source. CommandText to SqlDataReader. . to DataReader by
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 Sqldatareader Sqldatareader hasrows hasrows() () Properties rd Objects
HASROWS() Gets a value that indicate whether that sqldatareader contains one Gets a value that indicate whether that sqldatareader contains one or more rows . or more rows .
Imports Imports System. System.Data. Data.SqlClient SqlClient Dim Dim con con As New As New SqlConnection SqlConnection Dim Dim cmd cmd As New As New SqlCommand SqlCommand Dim Dim rd rd As As SqlDataReader SqlDataReader con. con.ConnectionString ConnectionString = = " "Data Source=. Source=.\ \SQLEXPRESS; SQLEXPRESS;AttachDbFilename Instance= Instance=True" True" Data AttachDbFilename=| =|DataDirectory DataDirectory| |\ \FitNation. FitNation.mdf; mdf;Integrated Integrated Security= Security=True; True;User User cmd. cmd.Connection Connection = = con con con. con.Open Open() () cmd. cmd.CommandText CommandText = " Password= '" & Password= '" & TextBox = "select select Username, Username,Password TextBox2 2. .Text & "'" Text & "'" Password from from Trianer Trianer where Username = '" & where Username = '" & TextBox TextBox1 1. .Text & "' Text & "' and and rd = rd = cmd. cmd.ExecuteReader ExecuteReader If If rd. rd.HasRows HasRows Then Then Form Form4 4. .Show() Show() Else Else MsgBox MsgBox(" ("invalid invalid username, username,password password") ") End If End If
THE END THE END