码迷,mamicode.com
首页 > 数据库 > 详细

获取SqlDataReader的列名

时间:2016-02-16 20:38:18      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

   SqlConnection thisConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
            // Open connection
            thisConnection.Open();
            // Create command for this connection
            SqlCommand thisCommand = thisConnection.CreateCommand();
            // Specify SQL query for this command
            thisCommand.CommandText = sCommandText;
            // Execute DataReader for specified command
            SqlDataReader thisReader = thisCommand.ExecuteReader();
            // While there are rows to read
            //

            //
            View_LogDetailEntity = new List<CView_LogDetail>();//初始化集合

 string sColumnName = string.Empty;

  while (thisReader.Read())
            {
                CView_LogDetail myCView_LogDetail = new CView_LogDetail();
                for (int i = 0; i < thisReader.FieldCount; i++)
                {

                      sColumnName = thisReader.GetName(i).Trim();

                }

           }

 

获取SqlDataReader的列名

标签:

原文地址:http://www.cnblogs.com/ChineseMoonGod/p/5193619.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!