Header questions

G

Gmansky

Hi,

I have a page where I want to place the title of the song on the header. I
am getting an error:

System.NullReferenceException: Object variable or With block variable not
set.

I have the usual query and repeater on my page_load. What is the proper way
of placing the data field ('Title') on the <header Template>?

I placed the codes here for reference.

//......................................................
Sub Page_Load
SongID = Request.QueryString("SongID")
If SongID <> "" Then
If Not Page.IsPostBack Then
DBConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Songs.mdb")
DBConnection.Open()
End If
SQLString = "SELECT Title, Type, Number, Text FROM Lyrics
INNER JOIN Songs ON Lyrics.Record = Songs.Record
WHERE Songs.Record=" & SongID & " order by type, number "
DBCommand = New OleDbCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
SongRepeater.DataSource = DBReader
SongRepeater.DataBind()
DBReader.Close()
DBConnection.Close()
End If
End Sub

Function displayTitle(zTitle)
Console.Write(zTitle)
End Function

//................................
<body style="FONT-FAMILY: arial">
<h2>Song List
</h2>
<% Response.Write(DateTime.Now.ToString()) %>
<hr size="1" />
<form runat="server">
<p>
<asp:Repeater id="SongRepeater" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="3"
style="border-collapse: collapse" width="400">
<tr style="background-color:#F0F0F0">
<th width="400">
<font face="Arial" size="2">

<%#displayLyrics(Container.DataItem("Title"))%> </font>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<font face="Arial" size="2"><strong> <%#
displayType(Container.DataItem("Type"),Container.DataItem("Number")) %>
</strong>
<br />
<%#displayLyrics(Container.DataItem("Text"))%>
<br />
</font></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</p>
<p>
</p>
</form>
</body>


//......................................................
Thanks in advance,
George
 
K

Karl

Gmansky, I think I see the problem. Pseudocode of your code is:

If Page isn't postback then
Create a connection
Open a connection
end
Get Data
Close your connection

You are only creating and opening a connection if you aren't in postback,
but you are ALWAYS trying to get data and closing the connection. You can't
get data if your connection isn't created and opened, and you certainly
can't close it.

If Page Isn't postback then
Create/Open connection
Get Data
Close connection
End if

Karl
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top