ASPNet_ADOdotNet1
-
Upload
chandrabhan-pradhan -
Category
Documents
-
view
219 -
download
0
Transcript of ASPNet_ADOdotNet1
-
8/2/2019 ASPNet_ADOdotNet1
1/17
-
8/2/2019 ASPNet_ADOdotNet1
2/17
ADO.NET is the new database technology of
the .NET (Dot Net) platform, and it builds
on Microsoft ActiveX Data Objects (ADO).
ADO.NET is an integral part of the .NET
Compact Framework, providing access to
relational data, XML documents, and
application data.
-
8/2/2019 ASPNet_ADOdotNet1
3/17
You can use ADO.NET to access data by using
the new .NET Framework data providers
which are:
Data Provider for SQL Server (System.Data.SqlClient).
Data Provider for OLEDB (System.Data.OleDb).
Data Provider for ODBC (System.Data.Odbc). Data Provider for Oracle (System.Data.OracleClient).
-
8/2/2019 ASPNet_ADOdotNet1
4/17
There are two central components ofADO.NET classes:
1. DataSet
2. .NET Framework Data Provider.
Data Provider is a set of components including: the Connection object (SqlConnection, OleDbConnection, OdbcConnection, OracleConnection)
the Command object (SqlCommand, OleDbCommand, OdbcCommand, OracleCommand)
the DataReader object (SqlDataReader, OleDbDataReader, OdbcDataReader, OracleDataReader)
and the DataAdapter object (SqlDataAdapter, OleDbDataAdapter, OdbcDataAdapter,OracleDataAdapter).
DataSet object represents a disconnected cache of data which ismade up of DataTables and DataRelations that represent theresult of the command.
-
8/2/2019 ASPNet_ADOdotNet1
5/17
-
8/2/2019 ASPNet_ADOdotNet1
6/17
-
8/2/2019 ASPNet_ADOdotNet1
7/17
Right click on Website name, select Add New
Item.
Select SqlServerDatabase Object
Give Proper name to Your database.
Done
-
8/2/2019 ASPNet_ADOdotNet1
8/17
1. Add .NET Data Provider namespace.
using System.Data.SqlClient;
2. Making Connection String
public string ConString= "Integrated Security=SSPI;" + "InitialCatalog=Northwind;" + "Data Source=SONY\\MYSQLSERVER;" ;
3. Complete Code
-
8/2/2019 ASPNet_ADOdotNet1
9/17
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = null; string constr ="Integrated Security=SSPI;" + "Initial Catalog=Northwind;" + "Data
Source=CBP\\Employee;";
try
{
// setup the database connection
con = new SqlConnection(constr);
con.Open();
Response.Write("connection established successfully");
}
catch (Exception ex)
{
Response.Write("Error in connection : " + ex.Message);
//MessageBox.Show("Error in connection : " + ex.Message);
}
finally
{
// dispose of open objects
if (con != null)
con.Close();
} //finally
}
-
8/2/2019 ASPNet_ADOdotNet1
10/17
The DataSet is similar to an array of
disconnected Recordset objects. It supports disconnected
data access and operations, allowing greater scalability
because you no longer have to be connected to the database
all the time. DataSet is a copy of an extracted data being
downloaded and cached in the client system.
-
8/2/2019 ASPNet_ADOdotNet1
11/17
The DataSet object is made up of two objects:
DataTableCollection object containing null or
multiple DataTable objects (Columns, Rows, Constraints).
DataRelationCollection object containing null or
multiple DataRelation objects which establish a parent/child
relation between two DataTable objects.
-
8/2/2019 ASPNet_ADOdotNet1
12/17
Create dataSet
DataSet dset = new DataSet();
A DataSet is a container; therefore, you have to fill it with data.
-
8/2/2019 ASPNet_ADOdotNet1
13/17
string strSql = "select * from tbl_emp";
SqlDataAdapter dadapter = new SqlDataAdapter(); dadapter.SelectCommand = new SqlCommand(strSql, con);
//Fill Data Set
dadapter.Fill(dset);
-
8/2/2019 ASPNet_ADOdotNet1
14/17
//Create a DataSet
DataSet dset = new DataSet();
//Create Data Table
DataTable dt = new DataTable();
//Fill Data Set
dadapter.Fill(dset);
//Fill DataTable via DataSet
dt = dset.Tables[0];
con.Close();
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = dt.Columns[1].ToString();
DropDownList1.DataBind();
-
8/2/2019 ASPNet_ADOdotNet1
15/17
DataAdapter object is like a bridge that links the database and a
Connection object with the ADO.NET-managedDataSet objectthrough its SELECT and action query Commands. It specifieswhat data to move into and out of theDataSet. Often, thistakes the form of references to SQL statements or storedprocedures that are invoked to read or write to a database.
The DataAdapter provides four properties that allow us tocontrol how updates are made to the server:
SelectCommand
UpdateCommand
InsertCommand DeleteCommand
The four properties are set to Command objects that are used
when data is manipulated.
-
8/2/2019 ASPNet_ADOdotNet1
16/17
The DataAdapter includes three main methods:
Fill (populates a DataSet with data).
FillSchema (queries the database for schema information that
is necessary to update).
Update (to change the database, DataAdapter calls
the DeleteCommand, the InsertCommand and the
UpdateCommand properties).
-
8/2/2019 ASPNet_ADOdotNet1
17/17
CONTINUE IN PART 2-