C# 循环DataSet表里的数据

cs:DataSet ds = DbSqlClient.Query(sql);

页面:
foreach (System.Data.DataRow dr in ds.Tables["ds"].Rows)
{
    Response.Write(dr["AreaID"].ToString());
    Response.Write(dr[1].ToString()+"<br>");

}



foreach (System.Data.DataRow dr in ds.Tables["ds"].Rows)
{
    Response.Write(dr["AreaID"].ToString());
    Response.Write(dr[1].ToString()+"<br>");

}

或:
页面:<%=getTable()%>

cs:
DataSet ds = DbSqlClient.Query(sql);

public string getTable()
    {
        StringBuilder str = new StringBuilder();
        str.Append("<select>");
        foreach (System.Data.DataTable dtrow in ds.Tables)
        {
            foreach (System.Data.DataRow dr in dtrow.Rows)
            {
                str.Append("<option value="+dr["AreaID"].ToString()+">" + dr[1].ToString() + "</option>");

            }
        }
        str.Append("</select>");
        return str.ToString();
    }

你可能感兴趣的:(Data)