獲取內存表中的數據

一、DateTable  dt  = Coeno.BU.BUs.QueryBUIDInfo().Tables[0];   (命名空間名稱、類名、方法名)

       dorpBU.DateSource=dt;    (獲取對象)

       dorpBU.DateTextField=dt.Columns["BU"].ToString();    (獲取該表列的集合)

       dropBU.DataValueField = dtBU.Columns["BU"].ToString();

       dropBU.DataBind();  (數據綁定)

       dropBU.Items.Insert(0,new ListItem("ALL","ALL"));  (將指定的ListItem插入到集合指定索引的位置)

二、 public static DataSet QueryBUIDInfo()

      {

       string sql ="SELECT * FROM BU表 where  enableflag=' " +"1"+" ' order by BU"   ;

            SqlConnection con   =  new SqlConnection (con);

            SqlDataAdapter dad = new SqlDataAdapter(sql, con);

            DataSet dst = new DataSet();

             try

             {

               con.Open();

       dad.Fill(dst,"QueryBU");

             }

    catch(SqlException e)

             {

       throw new Exception(e.Message);

             }

            finally

            {

      con.Close();

            }

            return  dst;

}

猜你喜欢

转载自www.cnblogs.com/ximi07/p/10233435.html