读取数据库中空字段的处理方法如下

#region 查询所有的产品信息

        /// <summary>

        /// 查询所有的产品信息

        /// </summary>

        /// <returns></returns>

        public List<Product> QueryAllProductInfo()

        {

            List<Product> productShowList = new List<Product>();

            Product product = null;

            string sql = " use QiGuang select * from Product ";

            try

            {

                DataTable table = DBHelper.GetDataSet(sql);

                foreach (DataRow row in table.Rows)

                {

                    product = new Product();

                    product.Id =(int)row["Id"];

                    product.ISBN = row.IsNull("ISBN")? "":(string)row["ISBN"];

                    product.ScreenSize = row.IsNull("ScreenSize") ? "" : (string)row["ScreenSize"];

                    product.ProcessType = row.IsNull("ProcessType") ? "" : (string)row["ProcessType"];

                    product.WorkSystem = row.IsNull("WorkSystem") ? "" : (string)row["WorkSystem"];

                    productShowList.Add(product);

                }

                return productShowList;

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

                throw e;

            }

        }

        #endregion

 

#region 查询所有的关博览胜列表

        /// <summary>

        /// 查询所有的关博览胜列表

        /// </summary>

        /// <returns></returns>

        public static List<NwebCn_rddtSortModel> GetAllNwebCn_rddtSortModelInfo()

        {

            List<NwebCn_rddtSortModel> list = new List<NwebCn_rddtSortModel>();

            NwebCn_rddtSortModel rddtSort = null;

            string sql = "select * from NwebCn_rddtSort ";

            OleDbDataReader reader = DBHelper.ExecuteReader(sql);

            while (reader.Read())

            {

                rddtSort = new NwebCn_rddtSortModel();

                rddtSort.ID = Convert.ToInt32(reader[0].ToString());

                rddtSort.SortNameSi = reader[1].ToString();

                rddtSort.SortNameTr = reader[2].GetType() == null ? "" : reader[2].ToString();

                rddtSort.SortNameEn = reader[3].GetType() == null ? "" : reader[3].ToString();

                rddtSort.ViewFlagSi = reader[4].ToString() == "True" ? true : false;

                rddtSort.ViewFlagTr = reader[5].ToString() == "True" ? true : false;

                rddtSort.ViewFlagEn = reader[6].ToString() == "True" ? true : false;

                list.Add(rddtSort);

            }

            reader.Close();

            reader.Dispose();

            return list;

        }

#endregion

 

2.DataList和Repeater控件的区别:DataList控件布局容易是页面混乱,而Repeater控件不会对页面不局造成改动!

作者:江宁织造
博客:http://www.cnblogs.com/wgx0428/
原文地址:https://www.cnblogs.com/wgx0428/p/2514002.html