遍历datatable的方法汇总

遍历datatable的方法
方法一:
DataTable dt = dataSet.Tables[];
for(int i = ; i < dt.Rows.Count ; i++)
{
string strName = dt.Rows[i]["字段名"].ToString();
} 方法二:
foreach(DataRow myRow in myDataSet.Tables["temp"].Rows)
{
var str = myRow[].ToString();
} 方法三:
foeach(DataRow dr in dt.Rows)
{
object value = dr["ColumnsName"];
} 方法四:
DataTable dt=new DataTable();
foreach(DataRow dr in dt.Rows)
{
for(int i=;i<dt.Columns.Count;i++)
{
dr[i];
}
} 绑定DataTable到Reapter。
if (dtb_xx.Rows.Count > )
{
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>
上一篇:AWS Redshift typical error and potential root cause:


下一篇:巧用CSS3伪类选择器自定义checkbox和radio的样式