C# 如何在不使用IEnumerator的情况下通过while循环从数据集中的表中获取偶数列

C# 如何在不使用IEnumerator的情况下通过while循环从数据集中的表中获取偶数列,c#,asp.net,while-loop,dataset,C#,Asp.net,While Loop,Dataset,我只想通过使用while循环而不使用IEnumerator来获得偶数列。While循环必须采用索引格式 代码如下: protected void Page_Load(object sender, EventArgs e) { string query = "SELECT * FROM Notifications_ WHERE News_Status='1'"; connection obj_con= new connectio

我只想通过使用while循环而不使用IEnumerator来获得偶数列。While循环必须采用索引格式

代码如下:

protected void Page_Load(object sender, EventArgs e)
        {

            string query = "SELECT * FROM Notifications_ WHERE News_Status='1'";

            connection  obj_con= new connection();


            SqlCommand myCommand = new SqlCommand(query);

            DataSet ds = obj_con.executeQueryDataSet(myCommand);

            String temp_data = "<table> <tr><h2 align='center' style='background-color:#00254c; color:white; vertical-align:top'>Highlights</h2></tr><tr><td> </td></tr><tr><td> </td><td> </td></tr><tr><td></td><td> </td></tr>";



            foreach (DataTable table in ds.Tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    temp_data = temp_data + "<tr></tr><tr><td style='background-color:gray; color:white'><b>" + row["News_Day"] + "</b></td></tr><tr><td style='background-color:#f6f6f6; color:#00254c'><h2 align='center'>" + row["News_date"] + "</h2></td><td style='color:#00254c'><b>" + row["News_title"] + "</b></td></tr><tr><td></td><td><a href=" + row["News_Link"] + " style='color:GrayText; text-decoration:none'>" + row["News_Desc"] + "</td></tr>";
                }
            }

            this.notification_data.InnerHtml = temp_data + "</table>";
        }
受保护的无效页面加载(对象发送方,事件参数e)
{
string query=“SELECT*FROM Notifications”WHERE News\u Status='1';
连接对象=新连接();
SqlCommand myCommand=新的SqlCommand(查询);
数据集ds=obj_con.executeQueryDataSet(myCommand);
字符串temp_data=“Highlights”;
foreach(ds.Tables中的数据表)
{
foreach(table.Rows中的DataRow行)
{
临时数据=临时数据+“”+行[“新闻日”]+“”+行[“新闻日期”]+“”+行[“新闻标题”]+“”+行[“新闻描述”]+“”;
}
}
this.notification_data.InnerHtml=temp_data+“”;
}

您可以这样尝试,如本示例代码所示

string[] columnNames = (from dc in table.Columns.Cast<DataColumn>()
                        select dc.ColumnName).ToArray();


do
    {
       if (i%2==0)
           //do something here
        i++;
    } while (i < columnNames.Length);
string[]columnNames=(来自table.Columns.Cast()中的dc)
选择dc.ColumnName).ToArray();
做
{
如果(i%2==0)
//在这里做点什么
i++;
}而(i
您不能从SQL端管理它吗?看不,我想这样做