using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; namespace DataReaderC { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Create and open aconnection to Northwind database SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=Northwind;Integrated Security=TRUE"); conn.Open(); //Create a SQL statement to get rows from the Employees table string queryString = "SELECT CustomerID, CompanyName FROM dbo.Customers"; //Create the command object SqlCommand com = new SqlCommand(queryString, conn); //Call the command's ExecuteReader method SqlDataReader dr = com.ExecuteReader(); //Loop through the datareader to output the employee names while (dr.Read()) { //dr.GetString(1); ListBox1.Items.Add(dr["CustomerID"].ToString() + " " + dr["CompanyName"].ToString()); } //Close the datareader & connection dr.Close(); conn.Close(); } } }