如何从数据库取一个表的值 不能用REAPTOR 还有GRIDVIEW 用TABLE显示要怎么操作我在后台写了方法在前台如何调用急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 aspx页面:<table> <%foreach(System.Data.Row row in dt.Rows){%> <%=row["cellname"]%> <%}%></table> DataSet ds = GetDataSet();//假设这里获取到了DS,表有3列StringBuilder sbuilder = new StringBuilder();sbuilder.Append("<table>");for(int i =0;i<ds.Tables[0].Rows.Count;i++){ sbuilder.Append("<tr>"); sbuilder.Append("<td>" + ds.Tables[0].Rows[i][0].ToString() + "</td>"); sbuilder.Append("<td>" + ds.Tables[1].Rows[i][0].ToString() + "</td>"); sbuilder.Append("<td>" + ds.Tables[2].Rows[i][0].ToString() + "</td>"); sbuilder.Append("</tr>");}sbuilder.Append("</table>");Response.Write(sbuilder.ToString()); 支持在后台用stringbuilder 然后输出 或者做成方法 protected string GetTableString(){ DataSet ds = GetDataSet();//假设这里获取到了DS,表有3列StringBuilder sbuilder = new StringBuilder();sbuilder.Append("<table>");for(int i =0;i<ds.Tables[0].Rows.Count;i++){ sbuilder.Append("<tr>"); sbuilder.Append("<td>" + ds.Tables[0].Rows[i][0].ToString() + "</td>"); sbuilder.Append("<td>" + ds.Tables[1].Rows[i][0].ToString() + "</td>"); sbuilder.Append("<td>" + ds.Tables[2].Rows[i][0].ToString() + "</td>"); sbuilder.Append("</tr>");}sbuilder.Append("</table>");return sbuilder.ToString();}<asp:Label ID="lblInfo" runat="server" Text="<%=GetTableString()%>"></asp:Label> using(SqlDataReader dr=cmd.ExecuteReader(CommandBehavior.CloseConnection)){//<table> 字符串} 前台还是Table前台:<table boder=1><tr><td>第一条记录:<%=data1%></td></tr></table>后台定义一个变量 public static string data1="";data1 = ds.table[0].rows[0][0].tostring()看界面,即可输出第一行的记录,如上只是一个例子ds数据用循环遍历下即可。。赋值感念一样。 做个表映射的MODEL然后建立一个泛型集合List<MODEL>=ExcuteReader();把数据都读取到这个集合里然后FOREACH开始遍历吧…… 一个if判断的问题,见鬼了 winform 中mdi窗体内的子窗体位子问题 请问值类型 数值类型 是一回事吗? 有什么关系?具体说说。 C#向现有的文本文件中插入数据 频繁连接数据库的问题 如何要datagridview列的顺序按我的要求出现 一个关于webrequest的问题 菜鸟求救思归、邹健等大侠:HTTP、XML 编程 .net中com对象如何从object转化为可操作的对象?? 存储过程in是如何用的? C#Tcp网络编程 如何判断文件发送完毕? 如何使用IDataReader
<%foreach(System.Data.Row row in dt.Rows){%>
<%=row["cellname"]%>
<%}%>
</table>
sbuilder.Append("<table>");
for(int i =0;i<ds.Tables[0].Rows.Count;i++)
{
sbuilder.Append("<tr>");
sbuilder.Append("<td>" + ds.Tables[0].Rows[i][0].ToString() + "</td>");
sbuilder.Append("<td>" + ds.Tables[1].Rows[i][0].ToString() + "</td>");
sbuilder.Append("<td>" + ds.Tables[2].Rows[i][0].ToString() + "</td>");
sbuilder.Append("</tr>");
}sbuilder.Append("</table>");
Response.Write(sbuilder.ToString());
protected string GetTableString()
{
DataSet ds = GetDataSet();//假设这里获取到了DS,表有3列StringBuilder sbuilder = new StringBuilder();
sbuilder.Append("<table>");
for(int i =0;i<ds.Tables[0].Rows.Count;i++)
{
sbuilder.Append("<tr>");
sbuilder.Append("<td>" + ds.Tables[0].Rows[i][0].ToString() + "</td>");
sbuilder.Append("<td>" + ds.Tables[1].Rows[i][0].ToString() + "</td>");
sbuilder.Append("<td>" + ds.Tables[2].Rows[i][0].ToString() + "</td>");
sbuilder.Append("</tr>");
}sbuilder.Append("</table>");
return sbuilder.ToString();
}
<asp:Label ID="lblInfo" runat="server" Text="<%=GetTableString()%>"></asp:Label>
{
//<table> 字符串
}
前台:
<table boder=1>
<tr>
<td>
第一条记录:<%=data1%>
</td>
</tr>
</table>后台
定义一个变量 public static string data1="";
data1 = ds.table[0].rows[0][0].tostring()
看界面,即可输出第一行的记录,如上只是一个例子
ds数据用循环遍历下即可。。赋值感念一样。
然后建立一个泛型集合
List<MODEL>=ExcuteReader();
把数据都读取到这个集合里然后FOREACH开始遍历吧……