利用同一條Connection連線執行多次Command命令

using (myConn = new SqlConnection(m_strConnectionString))
{
    myConn.Open();
    using (SqlCommand myCommand1 = new SqlCommand(strSql, myConn))
    {
        using (SqlDataAdapter myAdp = new SqlDataAdapter(myCommand1))
        {
            ds = new DataSet();
            myAdp.Fill(ds, "RichMoney");
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

            //第一次運用   
            strSql = " select * from first ";
            myCommand1.CommandText = strSql;
            ds = new DataSet();
            myAdp.Fill(ds, "RichMoney");

            //第二次運用   
            strSql = " select * from second ";
            myCommand1.CommandText = strSql;
            ds1 = new DataSet();
            myAdp.Fill(ds1, "RichMoney");
        }
    }
}

留言