private void btnLoadData_Click(object sender, System.EventArgs e)
        {
            // Create a SqlConnection
            SqlConnection cnn = new SqlConnection("Data Source=(local);" +
                                                  "Initial Catalog=Northwind;Integrated Security=SSPI");
            // Create a SqlCommand
            SqlCommand cmd = cnn.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT * FROM Suppliers";
            // Set up the DataAdapter and fill the DataSet
            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;
            SuppliersDataSet ds = new SuppliersDataSet();

            da.Fill(ds, "Suppliers");
            // Dump the contents of the DataSet
            foreach (SuppliersDataSet.SuppliersRow suppRow in ds.Suppliers)
            {
                lbData.Items.Add(suppRow.SupplierID + " " + suppRow.CompanyName);
            }
        }
Example #2
0
  	 private void btnLoadData_Click(object sender, System.EventArgs e)
	 {
			// Create a SqlConnection
			SqlConnection cnn = new SqlConnection("Data Source=(local);" +
			"Initial Catalog=Northwind;Integrated Security=SSPI");
			// Create a SqlCommand
			SqlCommand cmd = cnn.CreateCommand();
			cmd.CommandType = CommandType.Text;
			cmd.CommandText = "SELECT * FROM Suppliers";
			// Set up the DataAdapter and fill the DataSet
			SqlDataAdapter da = new SqlDataAdapter();
			da.SelectCommand = cmd;
			SuppliersDataSet ds = new SuppliersDataSet();
			da.Fill(ds, "Suppliers");
			// Dump the contents of the DataSet
			foreach (SuppliersDataSet.SuppliersRow suppRow in ds.Suppliers)
			{
			  lbData.Items.Add(suppRow.SupplierID + " " + suppRow.CompanyName);
			}
		}