ADO.net is an object oriented set of libraries that allows you to interact with data sources. You can connect your application with database, text file, an excel spreadsheet or an XML file.
You have to specify a Connection String;
string connectionString = "";
After that you have to provide a query;
string query = "Select * from ...";
Then connect with the database...
using (SqlConnection con = new SqlConnection(connectionString))
// Create the Command and Parameter objects.
SqlCommand cmd = new SqlCommand(query, con);
// Open the connection in a try/catch block.
SqlDataReader reader = cmd.ExecuteReader();
reader, reader, reader);
catch (Exception ex)
ADO.NET is a software component which is used to connect to the database and to fetch/submit the data. Below is simple example which uses the ADO.NET.
Please check below code and explanation,
Create a stored procedure like below to get the current month data.
CREATE PROCEDURE sp_GetData
SET NOCOUNT ON;
WHERE [DATE] >= DATEADD(month, datediff(month, 0, getdate()), 0)
AND [DATE] < DATEADD(DAY, DATEDIFF(day, 0, getdate()),0 )
Now below is the code to call the stored procedure and to bind the data.
private void BindGrid()
DataTable dt = new DataTable();fs
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("sp_GetData");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlcon;
sda.SelectCommand = cmd;
if(dt.Tables.Rows.Count > 0)
GridView1.DataSource = dt;
Label1.Text = "No Record to display";
Label1.Text = "Error while fetching the record" + ex.Message;
Asheej T K
ADO.NET gives data access services in the Microsoft .NET platform. You can use ADO.NET to access data by using the new .NET Framework data providers which are
SQL Server Database
System.Data.SqlClient – Namespace
SqlConnection - Connection object
SqlCommand – Command object
SqlDataReader or SqlDataAdapter
MS Access Database
System.Data.OleDb - Namespace
OledbConnection - Connection object
OledbCommand – Command Object
OledbDataReader or OledbDataAdapter
like about code you can connect Oracle and other database.
Thanks and regards
"IF YOU WANT TO SHINE LIKE A SUN FIRST YOU HAVE BURN LIKE IT".
Microsoft Certified Technology Specialist in .Net
ADO.NET is the replacement of the existing DAO approach, where you can work in dis connected mode. Intially connection is required only to load data and you can perform the update operation and save the changes to database.
ADO.NET offers various namespaces for working with different database.
System.Data.SqlClient - namespace used for working with SQL Server Database
System.Data.Oledb - namespace used for working with Access Database
System.Data.MySqlClient - namespace for working with MySql Database.
For all the namespace having few objects which used for performing database operations.
All is well.
Try and fail but don't fail and try
To communicate with database purpose in .net we go for ADO.net concept. There are 2 types of communication we are followed one is connectionless protocol and another one is connection oriented protocol.
Give respect to your work, Instead of trying to impress your boss.
Blog : http://naveens-dotnet.blogspot.in/