Prova questo codice:
codice:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub btnIndice_Click(ByVal sender As Object, ByVal e As System.EventArgs)
lblIndice.Text = "" 'Svuoto la label per generare un nuovo indice
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim drTitoli As OleDbDataReader
Dim drLezioni As OleDbDataReader
Dim str As String = ConfigurationManager.ConnectionStrings("TuaConnectionString").ConnectionString
cn = New OleDbConnection(str)
cn.Open()
Dim strQuery As String = "SELECT * FROM Capitoli ORDER BY Ordine_Apparizione_Capitolo"
cmd = New OleDbCommand(strQuery, cn)
drTitoli = cmd.ExecuteReader()
While (drTitoli.Read())
lblIndice.Text += "titolo:" & drTitoli("Nome_Capitolo") & "<hr>"
lblIndice.Text += "- " ' Apro elenco numerato
strQuery = "SELECT * FROM Lezioni"
strQuery += strQuery & " WHERE IDcapitolo = " & drTitoli("ID_Capitolo")
strQuery += strQuery & " ORDER BY Ordine_Apparizione_Lezione"
cmd = New OleDbCommand(strQuery, cn)
drLezioni = cmd.ExecuteReader()
While (drLezioni.Read())
lblIndice.Text += "
- " & drLezioni("Nome_Lezione") & ""
End While
drLezioni.Close()
lblIndice.Text += "
" 'Chiudo elenco numerato
End While
drTitoli.Close()
cn.Close()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Indice del libro</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnIndice" runat="server" OnClick="btnIndice_Click" Text="Genera indice" /></div>
<asp:Label ID="lblIndice" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
Dovrai metterci la stringa di connessione giusta, se non ne hai una inseriscila direttamente nel web.config che fa sempre comodo:
codice:
<connectionStrings>
<add name="TuaConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\tuaCartellaProgetto\App_Data\tuoDatabase.mdb" providerName="System.Data.OleDb"/>
</connectionStrings>
Questo codice l'avevo già pronto, funziona, ho solo rinominato i campi