2014-03-25 33 views
-1

这里是我的代码Vb.net:是否有可能返回SQL SELECT语句的结果HTML表

Protected Sub Submit_Click(sender As Object, e As EventArgs)  
Dim sSQL As String 
sSQL = "Select (ID),fromcur as 'From Currency',tocur as 'To Currency',rate as  'Conversion Rate',cast(convtimestamp as datetime) as 'Updated Time' 
from Locations.dbo.Uni_Currency_Exchange_Rates 
where fromCur = '" + FromCur.Text + "' and toCur = '" + ToCur.Text + "' order by ConvTimeStamp desc " 
Location2.SelectCommand = sSQL.ToString 
Dim command3 As New SqlCommand(sSQL, connection) 

???????????????? 

End Sub 

我需要生成HTML表的代码 这对于每个记录

创建行
<table> 
<th>ID</th> 
<th>From Currency</th> 
<th>To Currency</th> 
<th>Rate</th> 
<th>Update Time</th> 
<tr>1</tr>.............................. 
<tr>2</tr>.............................. 
............................. 
</Table> 

显示这样的结果。

ID |从货币|货币|价格|更新时间

1 | MVR | USD | 15.42 | 3/25/14 12:00:00

1 | MVR | EUR | 22.00 | 3/25/14 12:00:00

有没有简短的方法来实现这一目标?

在此先感谢

+0

您使用的是ASP.NET吗? 你可以创建一个'Table'对象并用循环填充你的行和单元格。 – Tim

+0

Ya其Asp.net 4.5(aspx页面) –

+0

在这种情况下,您使用MVC的是哪种类型的页面?形式? – RoughPlace

回答

1

这很容易。这种旧学校,但我不知道有任何更简单的方法来做到这一点。

创建表对象

Dim myTable as Table 

创建一个DataReader - 这里的伪代码

Dim dr as DataReader = command.executeReader 
while reader.Read() 
TableRow r = new TableRow() 
TableCell cell = new TableCell() 
cell.Text = reader(0) 
r.Cells.Add(cell) 
myTable.Rows.Add(r) 
next 

Table暴露为标题行和标题单元的对象,以及。这可能是最简单的方法。 (您可以为行中的每一列重复单元格创建和填充,将单元格添加到该行,然后将该行添加到表格中)

除非您想使用XML,序列化和XSLT,不知道任何其他方式来做到这一点...

+0

感谢您的帮助,我刚刚开始使用vbnet –

+0

您也可以将表格放在页面上(使用 Tim

+0

现在再次感谢它变得更容易。 –