2014-03-25 35 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

現在再次感謝它變得更容易。 –