检索单列数据 [英] Retrieve single column data

查看:49
本文介绍了检索单列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我是.NET的新手.
我必须从SQL Server上的表中获取两列数据.我必须将它们加起来并在HTML表中显示结果.

注意:我没有使用gridview!

谢谢!

Hi!
I am new to .NET .
I have to get two column of data from a table on an SQL-Server. I have to add them up and display the result in an HTML table.

Note: I am not using a gridview!

Thank you!

推荐答案

使用System.Text;//名称空间
使用System.Data;

using System.Text;//namesspace
using System.Data;

public void ConvertToHtml(DataTable dt)
{
StringBuilder sb=new StringBuilder();
sb.Append("<''table''>");
sb.Append("<body>");
sb.Append("<''tr''>");
sb.Append("<''td''>ColumnFirst<''td>ColumnSecond /td /tr>");
for(int i=0;i''<''dt.Rows.Count;i++)
{
sb.Append("<''tr><table><tbody><tr><td>"+dt.rows[i][ColumnFirst]+"/td /tr");
sb.Append("<''tr><table><tbody><tr><td>"+dt.rows[i][ColumnSecond]+"/td /tr");
}
sb.Append("</body>/table");
Div1.InnerHtml=sb.ToString();// add this to div runat="server" in aspx page
}
</td></tr></tbody></table></td></tr></tbody></table>



//注意删除所有''.
//给出正确的HTML结束标记.



//Note Remove All '' occurrence.
//give proper closing HTML Tag.


答案的第一部分已经被回答.
我将尝试回答第二部分.

The 1st part of your answer has already been answered.
I will try to answer the 2nd part.

srinivasvempa写道:
srinivasvempa wrote:

我必须将它们加起来并在HTML表格中显示结果.

I have to add them up and display the result in an HTML table.



在aspx页面的< td>中添加标签.您想要在其中显示值的html表的一部分.最初将其可见性设置为false.
从数据库中获取值后,添加它们(很简单).
将值分配给标签,并将其可见性设置为true.

让我知道我是否回答错了.



In your aspx page, add a label in the <td> part of the html table where you want to display the value. Initially set it''s visibility to false.
After you get the values from the database, add them (that''s easy).
Assign the value to the label and set it''s visibility to true.

Let me know if I got your question wrong.


要从sql server中仅选择2行,
To select only 2 rows from sql server,
Select Top 2 from tablename


并在意义上添加两行?
如果列数据类型为十进制,整数等,则只能使用Sum()运算符添加到sql查询中.


and add two rows in the sense what?
If columns datatype are decimal, integer, etc. then you can add in sql query only using Sum() operator.


这篇关于检索单列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆