遍历datatable的几种方法【转载】

遍历datatable的方法2009-09-08 10:02方法一:
DataTable dt = dataSet.Tables[0];
for(int i = 0 ; i < dt.Rows.Count ; i++)
{
   string strName = dt.Rows[i]["字段名"].ToString();
}   

方法二:
foreach(DataRow myRow in myDataSet.Tables["temp"].Rows)
{
      var str = myRow[0].ToString();
}   

方法三:
foeach(DataRow dr in dt.Rows)
{
     object value = dr["ColumnsName"];
}   

方法四:
DataTable dt=new DataTable();
foreach(DataRow dr in dt.Rows)
{
   for(int i=0;i<dt.Columns.Count;i++)
   {
dr[i];
   }
}   

绑定DataTable到Reapter。
if (dtb_xx.Rows.Count > 0)
        {
            rp_xx.DataSource = dtb_xx;
            rp_xx.DataBind();
        }
<asp:Repeater ID="rp_xx" runat="server">
       <ItemTemplate>
            <tr>
                  <td>
                      <div>
                            <ul class="ListHorizontally">
                                 <li>
                                      <div class="TCell1">
                                            <%#Eval("ID")%>
                                       </div>
                                  </li>
                                  <li>
                                       <div class="TCell2">
                                             <%#Eval("Name")%>
                                        </div>
                                  </li>
                            </ul>
                       </div>
                    </td>
                </tr>
            </ItemTemplate>
         </asp:Repeater>
方法五
DataRow[] dataRows = null;
dataRows = dataTable.Select(fieldParentID + "=‘" + treeNode.Tag.ToString() + "‘", dataTable.DefaultView.Sort);
foreach (DataRow dataRow in dataRows)
{ 

     DataRow dataRow = dataTable.Rows[i]; 

     ?? = dataRow[fieldParentID].ToString();
} 
时间: 2024-08-03 18:11:51

遍历datatable的几种方法【转载】的相关文章

java中遍历MAP的几种方法

java中遍历MAP的几种方法 Java代码 Map<String,String> map=new HashMap<String,String>();    map.put("username", "qq");    map.put("passWord", "123");    map.put("userID", "1");    map.put("em

【JAVA】遍历Map的四种方法

public static void main(String[] args) { Map<String, String> map = new HashMap<String, String>();  map.put("1", "value1");  map.put("2", "value2");  map.put("3", "value3");    //第一种:普

python遍历数组的两种方法的代码

工作过程中,把开发过程中较好的一些内容段备份一下,下面内容是关于python遍历数组的两种方法的内容,希望对小伙伴有用途. colours = ["red","green","blue"] for colour in colours: print colour # red # green # blue 下面的方法可以先获得数组的长度,然后根据索引号遍历数组,同时输出索引号 colours = ["red","gree

Java遍历集合的几种方法

遍历集合的几种方法 用不同的方法遍历集合. public interface Iterator:对Collection进行迭代的迭代器.迭代器取代了Java Collections FrameWork中的Enumeration import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; import java.util.List;

OpenCV2+入门系列(三):遍历图像的几种方法

根据OpenCV中Mat类型的结构和内存中存储方式,此处给出三种对图像进行遍历的方法.首先给出基础的读取图片代码,在中间替换三种遍历方法即可,本文中,程序将遍历图像并将所有像素点置为255,所有运行结果中命令行里的数字为程序执行时间. #include "stdafx.h" #include <opencv2/core/core.hpp> #include "highgui.h" #include <iostream> using names

遍历Hashtable的几种方法

直接上代码,代码中使用四种方法遍历Hashtable. using System; using System.Collections; namespace HashtableExample { class Program { static Hashtable hashtable = new Hashtable(); static void Main(string[] args) { hashtable.Add("first", "Beijing"); hashtab

遍历Map的两种方法

MAP集合遍历的两种方法 1.使用keyset()获得Map中的的key ,然后使用get方法获得这个key对应的value; 示例:Map<String,Integer> map = new HashMap<String,Integer>(); map.put("张三",15); map.put("李四",16); map.put("王五",17); Set ss = map.keyset(); Iterator<

SQL Server遍历表的几种方法 转载

SQL Server遍历表的几种方法 阅读目录 使用游标 使用表变量 使用临时表 在数据库开发过程中,我们经常会碰到要遍历数据表的情形,一提到遍历表,我们第一印象可能就想到使用游标,使用游标虽然直观易懂,但是它不符合面向集合操作的原则,而且性能也比面向集合低.当然,从面向集合操作的角度出发,也有两种方法可以进行遍历表的操作,总结起来,遍历表有下面几种方法. 使用游标 使用表变量 使用临时表 我的需求是:针对HR.Employees表,新增一列fullname,并取值firstname+lastn

java 遍历Map的4种方法

在Java中如何遍历Map对象 How to Iterate Over a Map in Java 在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都实现了Map接口,以下方法适用于任何map实现(HashMap, TreeMap, LinkedHashMap, Hashtable, 等等) 方法一 在for-each循环中使用entries来遍历 这是最常见的并且在大多数情况下也是最可取的遍历方式.在键值都需要时使用. [java] view