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.
Example
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()
{
InitializeComponent();
}
private void btnSelect_Click(object sender, EventArgs e)
{
SqlDataReader reader;
string connection = System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
SqlConnection con = new SqlConnection(connection);
con.Open();
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));
}
reader.Close();
con.Close();
}
}
}




SQL Server
C#.Net
ASP.Net
ADO.Net
jQuery
No comments:
Post a Comment