What is use of ADO.NET data service framework?

Posted by Bageshkumarbagi under C# on 6/22/2013 | Points: 10 | Views : 835 | Status : [Member] | Replies : 3
Hi,

What is ADO.NET data service framework? and what is use of this please give one real time example.


Thanks,
Bagesh Kumar Singh

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Raj.Trivedi on: 6/23/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello

ADO.NET framework helps you to connect to a Datasource i.e. Excel,MS-Access,MS-SQL,Oracle ETC

ADO is active data objects which contains classes for all the sources and methods to get data from database to the .NET Application.

Here is the example

Assume you want to fill a grid from database.

1.You will decide what data source are you using,In simple words which server you are going to use.We will take an example of MS-SQL

There are 4 important steps to achieve data from database

1.Connecting to the source.
2.Firing the Query (In .NET Language giving the command)
3.Get the data from query in a Adapter(Adapter Acts as a bridge to get data from database).
4.Store it in a Dataset(it stores the data in dataset to show it in a .NET Control

Code

Note :- You will have to import these 4 namespaces.

using system.data.sqlclient; // this is for connecting to SQL and firing command
using system.data; // this is to store data in dataset.


Suppose on a page load you are getting the data from sql to grid.

protected void Page_Load(object sender, EventArgs e)
{
// Creating the object of SQLConnection class to connect to SQL
SqlConnection sqlconn = new SqlConnection("Data Source=YourServer;Initial Catalog=YourDatabase;Persist Security Info=True;User ID=Usernameforsqlserver;Password=passwordforsqluser");
sqlconn.Open(); // opening the connection.
SqlCommand cmdins = new SqlCommand("your sql query",sqlconn);
SqlDataAdapter da = new SqlDataAdapter(); // creating the object of sql adapter
da.SelectCommand = new SqlCommand(cmdins); // passing the object of sqlcommand to select command if you are firing select query.
DataSet ds = new DataSet(); // Creating the object of dataset.
da.Fill(ds); // filling the dataset from dataadapter
Gridview1.DataSource = ds; // Now we need to assign the data source to the grid view,so that grid view knows from wher to pick up the data.
Gridview1.DataBind(); // Finally bind the data,if you miss this then the data will not be displayed in Gridview.
}

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 6/24/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks...


Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 6/24/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks...


Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response