2 different datalists on same aspx page

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
 
C

Chumley Walrus

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
 
G

Guest

See what happens if you give the second connection another name - I use
strconnection1 and strconnection2 with success - -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top