You must Sign In to post a response.
  • Category: .NET

    How you use ado.net(interview quotation)

    How you use ado.net i got this quotation at interview . Tell me sir/madam how to explain
  • #747211
    Hi,

    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.
    try
    {
    con.Open();
    SqlDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
    Console.WriteLine("\t{0}\t{1}\t{2}",
    reader[0], reader[1], reader[2]);
    }
    reader.Close();
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    Console.ReadLine();
    }


    Thanks

    Regards,
    Coding Defined
    www.codingdefined.com

  • #747217
    Hi,

    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

    AS
    BEGIN

    SET NOCOUNT ON;
    SELECT *
    FROM TableName
    WHERE [DATE] >= DATEADD(month, datediff(month, 0, getdate()), 0)
    AND [DATE] < DATEADD(DAY, DATEDIFF(day, 0, getdate()),0 )

    END
    GO



    Now below is the code to call the stored procedure and to bind the data.

    private void BindGrid()
    {
    try
    {
    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;
    sda.Fill(dt);
    if(dt.Tables[0].Rows.Count > 0)
    {
    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    else
    {
    Label1.Text = "No Record to display";
    }

    }
    catch(Exception ex)
    {
    Label1.Text = "Error while fetching the record" + ex.Message;
    }
    }


    Regards,
    Asheej T K

  • #747218
    Hi,

    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
    S.Suresh

    "IF YOU WANT TO SHINE LIKE A SUN FIRST YOU HAVE BURN LIKE IT".

  • #747219
    ADO.NET is part of an API in .NET framework which is used to connect to database and perform database operations such as CRUD operations(Insert/Update/Delete/Create). It has inbuilt classes and libraries used to perform database operations. Using ADO.NET you can connect to any database from any vendor(MSSQL/Orale/MySQL database). We have connected and disconnected architecture in order to deal with data.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #747221
    Hi,
    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.
    DataAdapter
    DataSet
    Command
    Connection

    All is well.
    Thanks,
    Dharma
    Editor,Mentor,MVM
    Try and fail but don't fail and try

  • #747280
    Thanks to all

  • #747363
    Hi,

    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.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments