DataTable的成员方法及其数据成员的调用

1.取数据成员:
            DataTable dt = AdDA.GetAdPos(keyword);
          WidthTextBox.Text = dt.Rows[0]["Width"].ToString();
          DataRow dr = dt.Rows[0];
           string str = dr["title"];
2.Datatable数据转存入ArrayList:
       private ArrayList allCitys;
        public void FillList(){
            DataTable dt = CityDA.GetAllCityStatu();
            allCitys = new ArrayList();
            foreach (DataRow dr in dt.Rows)
            {
                City city = new City(int.Parse(dr["City_ID"].ToString()), dr["city_name"].ToString());
                allCitys.Add(city);
            }
        }
3. 与CreateCommand配合使用,专用于存储过程的执行
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public static DataTable ExecuteSelectCommand(SqlCommand command)
        {
            DataTable table;
            try
            {
                command.Connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                table = new DataTable();
                table.Load(reader);
                reader.Close();
            }
            catch (Exception ex)
            {
                Utilities.LogError(ex);
                throw ex;
            }
            finally
            {
                command.Connection.Close();
            }
            return table;
        }

你可能感兴趣的:(Datatable)