Académique Documents
Professionnel Documents
Culture Documents
NET
Part 1
What is ADO.NET?
• ADO is ActiveX Data Objects
• Provides access to data sources like SQL Server,
Oracle etc.
• It includes .NET Framework data providers for
connecting to a database, executing commands, and
retrieving results.
• ADO.NET comes with 4 database client namespace
1. For SQL Server
2. For Oracle
3. ODBC data source
4. Any database exposed through OLE DB.
Connections
IDbConnection
System.Data.
DbConnection Common
System.Data.Oracle DbConnectionBase
OracleConnection Others…
SQLConnection
System.Data.SqlClient
Establishing connection
• To establish a connection there are three
components that we need to specify in the form
of connection string
• Server where the database resides
• database name/instance
• authentication details to connect to the
database
Creating database and table
• In the IDE, open the ViewServer
Explorer.
• Select the server and enter the
database name as ‘Employee’
• Add new table called ‘Employee’ with
EID and Name as shown below.
row = cmd.ExecuteNonQuery()
ResultL.Text = row.ToString()
conn.Close()
Example for ExecuteScalar()
Dim source As String
Dim conn As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim o As System.Object
source = "Data Source=DEEPA-PC\\VAIO_VEDB;Initial
Catalog=Employee;Integrated Security=True"
conn = New SqlClient.SqlConnection(source)
conn.Open()
cmd = New SqlClient.SqlCommand("SELECT COUNT(*) FROM
EMPLOYEE", conn)
o = cmd.ExecuteScalar()
ResultL.Text = "No of records" + o.ToString()
ResultL.Visible = True
conn.Close()
Creating and calling a stored
procedure
• Create new stored procedure.