示例#1
0
    public void Populate_Grid(object sender, EventArgs e)
    {
        OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/Northwind.mdb"));

        myConn.Open();
        OleDbCommand myComm = new OleDbCommand("SELECT * FROM Orders WHERE CustomerID=@CustomerID ORDER BY OrderID DESC", myConn);

        myComm.Parameters.Add("@CustomerID", OleDbType.VarChar).Value = CustomerId.SelectedValue;

        myComm.ExecuteNonQuery();
        OleDbDataAdapter da = new OleDbDataAdapter();
        DataSet          ds = new DataSet();

        da.SelectCommand = myComm;
        da.Fill(ds, "Orders");
        OleDbDataReader myReader = myComm.ExecuteReader();

        Grid1.ClearPreviousDataSource();
        Grid1.DataSource = myReader;
        Grid1.DataBind();

        myConn.Close();
    }
 protected void LoadCustomers(object sender, EventArgs e)
 {
     Grid1.ClearPreviousDataSource();
     Grid1.DataSourceID = "SqlDataSource4";
 }
 protected void LoadProducts(object sender, EventArgs e)
 {
     Grid1.ClearPreviousDataSource();
     Grid1.DataSourceID = "SqlDataSource2";
 }
 protected void LoadSuppliers(object sender, EventArgs e)
 {
     Grid1.ClearPreviousDataSource();
     Grid1.DataSourceID = "SqlDataSource1";
 }