473,396 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Header questions

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.D ataItem("Number")) %>
</strong>
<br />
<%#displayLyrics(Container.DataItem("Text"))%>
<br />
</font></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</p>
<p>
</p>
</form>
</body>
//.................................................. ....
Thanks in advance,
George
Nov 18 '05 #1
1 1216
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

"Gmansky" <gm*****@starmd.net> wrote in message
news:uA**************@TK2MSFTNGP11.phx.gbl...
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.D ataItem("Number")) %>
</strong>
<br />
<%#displayLyrics(Container.DataItem("Text"))%>
<br />
</font></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</p>
<p>
</p>
</form>
</body>
//.................................................. ....
Thanks in advance,
George

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Hattuari | last post by:
I'm learning C++ after having spent several years in the computer industry doing both system administration and engineering. I've written code in Perl, Bash, Pascal, Ada, C, Mathematica (hundreds...
31
by: Steven T. Hatton | last post by:
If a header is not necessarily a source file, and the sequences delimited by < and > in header names aren't necessarily valid source file names, what exactly is a header? -- p->m == (*p).m == p.m...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
5
by: Jim Holder | last post by:
I tried building libpcap and tcpdump from my Red Hat 7 RPMs. The tcpdump make couldn't find ioccom.h and sockio.h. When a header file is missing, how do you find it? Thanks.
8
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
3
by: fc2004 | last post by:
Hi, Is there any tools that could report where cyclic header dependency happens? this would be useful when working with a large project where tens or hundreds of headers files may form complex...
4
by: Christoph Scholtes | last post by:
Hi, I have some questions about header files: Say I have a file functions.c which contains a couple of functions. I have declared some structs in this file too. The structs are defined in...
16
by: wdh3rd | last post by:
Hi everyone. I'm new to C and I have a few questions: I am making files for permutations and combinations. Files to be made are perm.c, perm.h, combo.c, and combo.h. Since both combinations...
4
by: andre rodier | last post by:
Hello, I need to display or propose a jpeg image on a web page. When I need to display the image, I use this code : header("Content-Length: $fileSize") ; header("Content-Type: $type") ;...
1
by: RN1 | last post by:
Consider the following DataGrid: -------------------------------------------------------------------------------- <asp:DataGrid ID="dgMarks" AutoGenerateColumns="false" runat="server"> <Columns>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.