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; using System.Data; namespace CustomerOrdersC { public partial class frmOrderHistory : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(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(); SqlCommand com = new SqlCommand(); com.Connection = conn; com.CommandText = "CustOrderHist"; com.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter("@CustomerID", SqlDbType.NVarChar, 5); param.Value = txtCustomerID.Text; com.Parameters.Add(param); //Call the command's ExecuteReader method SqlDataReader dr = com.ExecuteReader(); ListBox1.Items.Clear(); //Loop through the datareader to output the products ordered while (dr.Read()) { //dr.GetString(1); ListBox1.Items.Add(dr["ProductName"] + " " + dr["Total"].ToString()); } //Close the datareader & connection dr.Close(); conn.Close(); } } }