There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
'Object variable or With block variable not set' Error


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
AlexClifford's Avatar
Junior Member with 3 posts.
 
Join Date: Jan 2005
Experience: Advanced
24-Jan-2005, 11:27 PM #1
'Object variable or With block variable not set' Error
Hi,

I am getting the following error when I load the page shown below:

Code:
Object variable or With block variable not set. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

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

Source Error: 


Line 215:	Response.Write ("<option selected value=""" & MonthCheck(MonthCount) & """>" & MonthCount & "</option>" & vbCrLf)
Line 216:Else
Line 217:	Response.Write ("<option value=""" & MonthCheck(MonthCount) & """>" & MonthCount & "</option>" & vbCrLf)
Line 218:End If
Line 219:
I'm stuck, I'm thinking it must be something to do with the Function, MonthCheck, but I'm not making much of it. Any help would be greatly appreciated, thank you.

Code:
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="person_edit.aspx.vb" Explicit="True" Inherits="Contractors.person_edit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
	<head>
		<title>Contractors and Consultants Induction Search Tool</title> 
		<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
		<meta name="vs_defaultClientScript" content="VBScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<meta http-equiv="content-type" content="text/html;charset=utf-8">
		<meta http-equiv="Content-Style-Type" content="text/css">
		<link rel="stylesheet" href="style.css" type="text/css">
	</head>
	<script runat="server" language="vb">
	Function MonthCheck(num)

		If Len(num) < 2 Then
			MonthCheck = "0" & num
		Else
			MonthCheck = num
		End If

	End Function
	</script>
	<%
	
	Dim MyConnection As SqlConnection
	Dim MyCommand As SqlCommand
	Dim MyReader As SqlDataReader
	Dim MyBinder
	Dim sSQL As String
	Dim nameSQL As String

	Dim SelectedPerson

	MyConnection = New SqlConnection("server=DBASESVR;uid=CSC;pwd=CSC!;database=Contractors")
	MyConnection.Open()
	SelectedPerson = CStr(Request.Form("SelectedPerson"))

	%>
	<body>
		<table cellspacing="0" cellpadding="0" border="0">
			<tr>
				<td width="20" background="images/topleft_corner.gif" height="20"></td>
				<td background="images/top_border.gif" height="20"></td>
				<td width="20" background="images/topright_corner.gif" height="20"></td>
			</tr>
			<tr>
				<td width="20" background="images/left_border.gif"></td>
				<td valign="top" bgcolor="#f5f5f5">
					<span class="title">Contractors and Consultants Database Search</span><br />
					<br />
					<br />
					<table align="center" width="600" cellpadding="10">
						<tr>
						<%

						If SelectedPerson = "" Then

						%>
							<td class="info" colspan="5">
								To edit a person's details, please select them from the listbox.<br />
								<br />
								<%

								nameSQL = "SELECT ID, VendorNo, DateIssued, Surname, FirstName, ContactNumber, Address FROM Contacts"
								MyCommand = New SqlCommand(nameSQL, MyConnection)
								MyReader = MyCommand.ExecuteReader
								Contractors.DataSource = MyReader
								Contractors.DataBind()

								%>
								<form runat="server">
								<asp:Repeater id="Contractors" runat="server">

								<HeaderTemplate>
								<select name="SelectedPerson" size="2" style="height:200px;">
								</HeaderTemplate>

								<ItemTemplate>
								<option value="<%#Container.DataItem("ID")%>"><%#Container.DataItem("FirstName")%> <%#Container.DataItem("Surname")%></option>
								</ItemTemplate>

								<FooterTemplate>
								</select>
								<br /><br />
								<input type="submit" name="Edit" value="Edit" style="width:50px" />
								</FooterTemplate>

								</asp:Repeater>
								</form>
							</td>
							<%

							Else


Dim MyCommand2 As SqlCommand
Dim MyReader2 As SqlDataReader
Dim MyBinder2
Dim sSQL2 As String
Dim nameSQL2 As String

nameSQL2 = "SELECT ID, VendorNo, DateIssued, Surname, FirstName, ContactNumber, Address FROM Contacts WHERE ID = " & SelectedPerson
MyCommand2 = New SqlCommand(nameSQL2, MyConnection)
MyReader2 = MyCommand2.ExecuteReader

While MyReader2.Read

Dim DateIssued
Dim DateDay
Dim DateMonth
Dim DateYear

DateIssued = Split(MyReader2.GetValue(2), "/")
DateDay = CInt(DateIssued(0))
DateMonth = CInt(DateIssued(1))
DateYear = CInt(DateIssued(2))

%>
<td class="info" colspan="5">
Edit the following fields then submit the changes.
<br /><br />
<form method="post" action="person_process.asp">
<table cellpadding="10">
<tr>
<td class="heading2">
First Name:
</td>
<td>
<input type="text" name="FirstName" value="<%=MyReader2.GetValue(4)%>" maxlength="50" style="width:200px" />
</td>
</tr>
<tr>
<td class="heading2">
Surname:
</td>
<td>
<input type="text" name="Surname" value="<%=MyReader2.GetValue(3)%>" maxlength="50" style="width:200px" />
</td>
</tr>
<tr>
<td class="heading2">
Address:
</td>
<td>
<input type="text" name="Address" value="<%=MyReader2.GetValue(6)%>" maxlength="50" style="width:200px" />
</td>
</tr>
<tr>
<td class="heading2">
Contact Number:
</td>
<td>
<input type="text" name="ContactNumber" value="<%=MyReader2.GetValue(5)%>" maxlength="50" style="width:200px" />
</td>
</tr>
<tr>
<td class="heading2">
Vendor Number:
</td>
<td>
<input type="text" name="VendorNo" value="<%=MyReader2.GetValue(1)%>" maxlength="50" style="width:200px" />
</td>
</tr>
<tr>
<td class="heading2">
Date Issued:
</td>
<td>
<select name="DayIssued" size="1">
<%

dim DayCount
DayCount = 1

Do While DayCount < 32

If CInt(DateIssued(0)) = CInt(DayCount) Then
	Response.Write ("<option selected value=""" & DayCount & """>" & DayCount & "</option>" & vbCrLf)
Else
	Response.Write ("<option value=""" & DayCount & """>" & DayCount & "</option>" & vbCrLf)
End If

DayCount = DayCount + 1

Loop ' END: Do While DayCount < 32

%>
</select>

<strong>:</strong>

<select name="MonthIssued" size="1">
<%

Dim MonthCount
dim MonthCheck
MonthCount = 1

Do While MonthCount < 13

If CInt(DateIssued(1)) = CInt(MonthCount) Then
	Response.Write ("<option selected value=""" & MonthCheck(MonthCount) & """>" & MonthCount & "</option>" & vbCrLf)
Else
	Response.Write ("<option value=""" & MonthCheck(MonthCount) & """>" & MonthCount & "</option>" & vbCrLf)
End If

MonthCount = MonthCount + 1

Loop ' END: Do While MonthCount < 13

%>
</select>

<strong>:</strong>

<select name="YearIssued" size="1">
<%

dim YearCount
YearCount = Year(Now) -1

Do While YearCount < (Year(Now) + 2)

If CInt(DateIssued(2)) = CInt(YearCount) Then
	Response.Write ("<option selected value=""" & YearCount & """>" & YearCount & "</option>" & vbCrLf)
Else
	Response.Write ("<option value=""" & YearCount & """>" & YearCount & "</option>" & vbCrLf)
End If

YearCount = YearCount + 1

Loop ' END: Do While YearCount < (Year(Now) + 2)

%>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Save" style="width:80px" />
<input type="hidden" name="personid" value="<%=SelectedPerson%>" />
</td>
</tr>
</table>
</form>
</td>
<%

End While

							MyConnection.Close()

						End If ' END: If SelectedPerson = ""

					%>
					</tr>
					</table>
					<br />
					<div style="text-align: right;"><a href="index.aspx">Index</a></div>
				</td>
				<td width="20" background="images/right_border.gif"></td>
			</tr>
			<tr>
				<td width="20" background="images/bottomleft_corner.gif" height="20"></td>
				<td background="images/bottom_border.gif" height="20"></td>
				<td width="20" background="images/bottomright_corner.gif" height="20"></td>
			</tr>
		</table>
	</body>
</html>
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:44 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.