Database Hierarchy (Dealing With Data Adapter,: Using System - Data.Oledb
Database Hierarchy (Dealing With Data Adapter,: Using System - Data.Oledb
Database Hierarchy (Dealing With Data Adapter,: Using System - Data.Oledb
ADO.NET cleanly factors data access from data manipulation into discrete components that can be
used separately or in tandem. ADO.NET includes .NET Framework data providers for connecting to a
database, executing commands, and retrieving results. Those results are either processed directly,
or placed in an ADO.NET DataSet object in order to be exposed to the user in an ad-hoc manner,
combined with data from multiple sources, or remoted between tiers. The ADO.NET DataSet object
can also be used independently of a .NET Framework data provider to manage data local to the
application or sourced from XML.
The ADO.NET classes are found in System.Data.dll, and are integrated with the XML classes found in
System.Xml.dll. When compiling code that uses the System.Data namespace
What is ADO.NET?
First, import the "System.Data.OleDb" namespace. We need this namespace to work with Microsoft
Access and other OLE DB database providers. We will create the connection to the database in the
Page_Load subroutine. We create a dbconn variable as a new OleDbConnection class with a
connection string which identifies the OLE DB provider and the location of the database. Then we
open the database connection:
To specify the records to retrieve from the database, we will create a dbcomm variable as a new
OleDbCommand class. The OleDbCommand class is for issuing SQL queries against database tables:
Create a DataReader
The OleDbDataReader class is used to read a stream of records from a data source. A DataReader is
created by calling the ExecuteReader method of the OleDbCommand object:
Using System.Data.OleDb;
sub Page_Load
end sub
Always close both the DataReader and database connection after access to the database is no
longer required:
dbread.Close()
dbconn.Close()
Structure
try
{
conn.Open();
}
catch (SqlException e)
{
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
log.Source = "My Application";
log.WriteEntry(e.ToString());
if (conn.State != ConnectionState.Open)
Console.WriteLine("Connection was not opened.");
}
finally
{
conn.Close();
}
Attackers often use information from an exception, such as the name of your server, database, or
table to mount a specific attack on your system