Tabelle dinamiche

martedì 05 ottobre 2004 - 16.12

mon78 Profilo | Junior Member

sto creando una web application in vb.net. In una web form vorrei inserire in codice che mi permette di creare dinamicamente una tabella in excel con i dati che prelevo da un database. Nn so proprio come fare. Mi potete aiutare? grazie mille.

scarface Profilo | Newbie

prova così:
response.buffer = true
Response.Clear
response.ContentType = "application/vnd.ms-excel"
response.AddHeader ("content-disposition", "attachment;filename=pippo.xls")
Dim strConn, strSql As String
strConn= System.Configuration.ConfigurationSettings.appSettings("tuaconn")
strSql = "SELECT * FROM miatabella"
Dim da As SqlDataAdapter = New SqlDataAdapter(strSql, strConn)
Dim ds= New DataSet()
da.Fill(ds, "tabella")
Dim prow As DataRow
Response.Write("<table border=1 bordercolor=lightsteelblue cellspacing=0 align=center>")
Response.Write("<tr><td><strong>Uno</strong></td><td><strong>Due</strong></td><td><strong>Tre</strong></td></tr>")
if ds.Tables("tabella").Rows.Count>0 then
For Each pRow In ds.Tables("tabella").Rows
Response.Write("<tr><td>" & pRow("cod1").ToString() & "</td><td>" & pRow("cod2").ToString() & "</td><td>" & "</td></tr>")
next
end if
Response.Write("</table>")
response.flush
response.end

Ciao

mon78 Profilo | Junior Member

grazie tante
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5