Wednesday 31 July 2013

Components of ADO.Net ,execute scalar and execute non query,difference asp .net web forms and asp .net mvc.



Component of ADO .Net  :

following are the important component of ADO .net


1.  Data Set

2.  Data Reader
3.  Data Adaptor
4.  Command
5.  Connection

DataSet :


1 . It is disconnected orient architecture that means there is no need of active connections during              work with dataset.
2 . It is a collection of data tables and relations between tables.
3 . It is used to hold multiple tables with data.
4 . It provides you with rich features like saving data as XML .


// Following method is used to bind gridview from database with connection.

protected​ void​ BindMyGridview()

{


SqlConnection​ connection  = newSqlConnection("Data Source=MyUsers;Integrated Security=true;Initial Catalog=MySampleDataBase") 
connection.Open();


SqlCommand​ command = new​ SqlCommand("select Fname,Lname,Jlocation from UserData",connection);


SqlDataAdapter​ dap =new SqlDataAdapter(command);

DataSet​ dst = new​ DataSet();


dap.Fill(dst); 

gvUserData.DataSource = dst; 

gvUserData.DataBind();


}

Data Reader :


1. It is used to read the data from database.
2. It is a read and forward only connection oriented architecture.
3. It fetch the data from database. 
4. It is used to iterate through result set that came from server.
5. It will read one record at a time.
6. It will fetch the data very fast when compared with dataset. 

// Following method is used to bind gridview from database with connection.

protected​ void​ BindMyGridview()

{


SqlConnection​ connection  = newSqlConnection("Data Source=MyUsers;Integrated Security=true;Initial Catalog=MySampleDataBase") 
{

connection.Open();

SqlCommand​ command = new​ SqlCommand("select Fname,Lname,Jlocation from UserData",connection);


SqlDataReader​ dr = cmd.ExecuteReader();

gvUserData.DataSource = dr; 

gvUserData.DataBind();

con.Close();
}
}

Data Adaptor :

1. It will acts as a Bridge between DataSet and database. 
2. Dataadapter object is used to read the data from database and bind that data to dataset. 
3. It is a disconnected oriented architecture. 

// Following method is used to bind gridview from database with connection.

protected​ void​ BindMyGridview()

{


SqlConnection​ connection  = newSqlConnection("Data Source=MyUsers;Integrated Security=true;Initial Catalog=MySampleDataBase") 
{

connection.Open();

SqlCommand​ command = new​ SqlCommand("select Fname,Lname,Jlocation from UserData",connection);

SqlDataAdapter dap = newSqlDataAdapter(command); 

DataSet​ dst = newDataSet();


dap.Fill(dst);

gvUserData.DataSource = dr; 

gvUserData.DataBind();


}

}

No comments:

Post a Comment