ADO.Net SQLCommand - ExecuteReader - DotNet and DataBase

Follow us on Facebook

SQL Server Mountain View Mountain View Mountain View

Wednesday, 1 August 2018

ADO.Net SQLCommand - ExecuteReader

The ExecuteReader() in .Netframework is a SqlCommand Object transfers the SQL queries to the Connection Object and generates a SqlDataReader Object based on the SQL statement supplied. When the ExecuteReader method in SqlCommand Object invokes, it will instantiate the SqlClient.SqlDataReader Object.

using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace EmployeeTimeSheet
    public partial class InsertEmployees : Form
        public InsertEmployees()

        private void btnSelect_Click(object sender, EventArgs e)
            SqlDataReader reader;
            string connection = System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
            SqlConnection con = new SqlConnection(connection);
            SqlCommand cmd = new SqlCommand("SELECT ID,Name FROM EmployeeInfo", con);
            reader = cmd.ExecuteReader();
            while (reader.Read())
                MessageBox.Show(reader.GetValue(0) + " - " + reader.GetValue(1) + " - " + reader.GetValue(2));

No comments:

Post a comment


Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.