2 different datalists on same aspx page

  • Thread starter Thread starter Chumley Walrus
  • Start date Start date
C

Chumley Walrus

I'm trying to display two different datalists on the same page; only
the first datalist displays, while the second does not display (and it
does have data matching the where clause):

<%@ Page Language="vb" Debug="true"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
dim todd = DateTime.Today.ToString ( "d" )
Dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\mydbase.mdb;"
Dim strSQL as string ="SELECT article, articleheader, articleID
FROM articles WHERE (dept = 'news') AND (articledate = #" & todd & "#)"

Dim Conn as New OLEDBConnection(strConn)
Dim Cmd as New OLEDBCommand(strSQL,Conn)
Conn.Open()
thedata.DataSource =
Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
thedata.DataBind()
End Sub
</script>
<html>
<head> <title>datalist test</title>
</head>

<body>
<asp:DataList id="thedata" runat="server"
RepeatColumns="1" RepeatDirection="vertical"
CellSpacing="3">
<ItemTemplate>
<b><%# Container.DataItem("articleheader")%></b>
<br><br><%# Container.DataItem("article")%>

</ItemTemplate>
</ASP:Datalist>

<script language="VB" runat="server">
sub t2
dim todd2 = DateTime.Today.ToString ( "d" )
Dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\mydbase.mdb;"
Dim strSQL as string ="SELECT article, articleheader, articleID
FROM articles WHERE (dept = 'features') AND (articledate = #" & todd2 &
"#)"
Dim Conn as New OLEDBConnection(strConn)
Dim Cmd as New OLEDBCommand(strSQL,Conn)
Conn.Open()
thedata2.DataSource =
Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
thedata2.DataBind()
end sub
</script>

<asp:DataList id="thedata2" runat="server"
RepeatColumns="1" RepeatDirection="vertical"
CellSpacing="3">
<ItemTemplate>
<b><%# Container.DataItem("articleheader")%></b>
<br><br><%# Container.DataItem("article")%>
</ItemTemplate>
</ASP:Datalist>
</body></html>

thanks in advance
chumley
 
I get an "ExecuteReader requires an open and available Connection. The
connection's current state is Closed" error when trying to combine the
two subs. Not sure what is involved with putting two subs in one
page_load
 
See what happens if you give the second connection another name - I use
strconnection1 and strconnection2 with success - -
 
Back
Top