470,815 Members | 1,317 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

DateTime Instance problem

I have created this DateTime object and instanced it I think correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateTime.Now.Hour,DateTime.Now.Minute ,DateTime.Now.Second);

I keep getting the below error:

Object reference not set to an instance of an object.

I don't know what the problem could be. Can someone help me with this? It
is driving me crazy. The stack info is as follows:

NullReferenceException: Object reference not set to an instance of an object.]
Sonar3.Controls.WeekendEvents.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\sonar3\controls\weekendevents.a scx.cs:41
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

Help!!!!!!!!!!! Please
Nov 19 '05 #1
5 1852
You need to provide more code from the page_load event. In most cases I've
seen like this, it is a scope issue, or a completely different statement
referencing a completly different object than the one you're assuming is
throwing the error.

--
Chris

"I am Sam" <Ia****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
I have created this DateTime object and instanced it I think correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateTime.Now.Hour,DateTime.Now.Minute ,DateTime.Now.Second);

I keep getting the below error:

Object reference not set to an instance of an object.

I don't know what the problem could be. Can someone help me with this?
It
is driving me crazy. The stack info is as follows:

NullReferenceException: Object reference not set to an instance of an
object.]
Sonar3.Controls.WeekendEvents.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\sonar3\controls\weekendevents.a scx.cs:41
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

Help!!!!!!!!!!! Please

Nov 19 '05 #2
When I debug and set a breakpoint It points out that the name is holding the
value {1/1/1} when the value should read todays date. I am rather confused
about this.

"I am Sam" wrote:
I have created this DateTime object and instanced it I think correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateTime.Now.Hour,DateTime.Now.Minute ,DateTime.Now.Second);

I keep getting the below error:

Object reference not set to an instance of an object.

I don't know what the problem could be. Can someone help me with this? It
is driving me crazy. The stack info is as follows:

NullReferenceException: Object reference not set to an instance of an object.]
Sonar3.Controls.WeekendEvents.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\sonar3\controls\weekendevents.a scx.cs:41
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

Help!!!!!!!!!!! Please

Nov 19 '05 #3
Thanx for replying so quickly Chris. The rest of the Page_Load is as follows:

public class WeekendEvents : System.Web.UI.UserControl
{
protected System.Data.SqlClient.SqlConnection ClubConn;
protected System.Data.SqlClient.SqlDataAdapter clubAdapt;
protected System.Data.SqlClient.SqlCommand clubcmd;
protected System.Data.DataSet dsClub;
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.Label Label1;
protected System.DateTime myClubNow1;

private void Page_Load(object sender, System.EventArgs e)
{
myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateTime.Now.Hour,DateTime.Now.Minute ,DateTime.Now.Second);
dsClub=new DataSet();

string strClubconn=ConfigurationSettings.AppSettings["ConnectionString"];
ClubConn=new SqlConnection(strClubconn);
ClubConn.Open();
string strClubcmdRead="SELECT EVNR_tbl.* FROM EVNR_tbl WHERE
EVNR_tbl._Date BETWEEN '" + myClubNow1.Date.ToShortTimeString() + "' AND '" +
myClubNow1.Date.AddDays(7).ToShortTimeString() + "'";
clubAdapt=new SqlDataAdapter(strClubcmdRead,ClubConn);
clubAdapt.Fill(dsClub,"EVNR_tbl");

Label1.Text=myClubNow1.ToString();
Repeater1.DataSource=dsClub;
Repeater1.DataBind();
}
}

"Chris" wrote:
You need to provide more code from the page_load event. In most cases I've
seen like this, it is a scope issue, or a completely different statement
referencing a completly different object than the one you're assuming is
throwing the error.

--
Chris

"I am Sam" <Ia****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
I have created this DateTime object and instanced it I think correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateTime.Now.Hour,DateTime.Now.Minute ,DateTime.Now.Second);

I keep getting the below error:

Object reference not set to an instance of an object.

I don't know what the problem could be. Can someone help me with this?
It
is driving me crazy. The stack info is as follows:

NullReferenceException: Object reference not set to an instance of an
object.]
Sonar3.Controls.WeekendEvents.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\sonar3\controls\weekendevents.a scx.cs:41
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

Help!!!!!!!!!!! Please


Nov 19 '05 #4
Hello,

Im not sure if this is the cause of your error, but is there any particular
reason you arent doing:

myClubNow1 = DateTime.Now;

--
Matt Berther
http://www.mattberther.com
Thanx for replying so quickly Chris. The rest of the Page_Load is as
follows:

public class WeekendEvents : System.Web.UI.UserControl
{
protected System.Data.SqlClient.SqlConnection ClubConn;
protected System.Data.SqlClient.SqlDataAdapter clubAdapt;
protected System.Data.SqlClient.SqlCommand clubcmd;
protected System.Data.DataSet dsClub;
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.Label Label1;
protected System.DateTime myClubNow1;
private void Page_Load(object sender, System.EventArgs e)
{
myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateTim
e.Now.Hour,DateTime.Now.Minute,DateTime.Now.Second );
dsClub=new DataSet();
string
strClubconn=ConfigurationSettings.AppSettings["ConnectionString"];
ClubConn=new SqlConnection(strClubconn);
ClubConn.Open();
string strClubcmdRead="SELECT EVNR_tbl.* FROM EVNR_tbl WHERE
EVNR_tbl._Date BETWEEN '" + myClubNow1.Date.ToShortTimeString() + "'
AND '" +
myClubNow1.Date.AddDays(7).ToShortTimeString() + "'";
clubAdapt=new SqlDataAdapter(strClubcmdRead,ClubConn);
clubAdapt.Fill(dsClub,"EVNR_tbl");
Label1.Text=myClubNow1.ToString();
Repeater1.DataSource=dsClub;
Repeater1.DataBind();
}
}
"Chris" wrote:
You need to provide more code from the page_load event. In most
cases I've seen like this, it is a scope issue, or a completely
different statement referencing a completly different object than the
one you're assuming is throwing the error.

--
Chris
"I am Sam" <Ia****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
I have created this DateTime object and instanced it I think
correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateT
ime.Now.Hour,DateTime.Now.Minute,DateTime.Now.Seco nd);
I keep getting the below error:

Object reference not set to an instance of an object.

I don't know what the problem could be. Can someone help me with
this?
It
is driving me crazy. The stack info is as follows:
NullReferenceException: Object reference not set to an instance of
an
object.]
Sonar3.Controls.WeekendEvents.Page_Load(Object sender, EventArgs e)
in
c:\inetpub\wwwroot\sonar3\controls\weekendevents.a scx.cs:41
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
Help!!!!!!!!!!! Please


Nov 19 '05 #5
I needed to create a new object of DateTime so that I can add days. I fixed
the problem. It wasn't DateTime it was the web control that the dateTime was
being bound to that was mistyped.

"Matt Berther" wrote:
Hello,

Im not sure if this is the cause of your error, but is there any particular
reason you arent doing:

myClubNow1 = DateTime.Now;

--
Matt Berther
http://www.mattberther.com
Thanx for replying so quickly Chris. The rest of the Page_Load is as
follows:

public class WeekendEvents : System.Web.UI.UserControl
{
protected System.Data.SqlClient.SqlConnection ClubConn;
protected System.Data.SqlClient.SqlDataAdapter clubAdapt;
protected System.Data.SqlClient.SqlCommand clubcmd;
protected System.Data.DataSet dsClub;
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.Label Label1;
protected System.DateTime myClubNow1;
private void Page_Load(object sender, System.EventArgs e)
{
myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateTim
e.Now.Hour,DateTime.Now.Minute,DateTime.Now.Second );
dsClub=new DataSet();
string
strClubconn=ConfigurationSettings.AppSettings["ConnectionString"];
ClubConn=new SqlConnection(strClubconn);
ClubConn.Open();
string strClubcmdRead="SELECT EVNR_tbl.* FROM EVNR_tbl WHERE
EVNR_tbl._Date BETWEEN '" + myClubNow1.Date.ToShortTimeString() + "'
AND '" +
myClubNow1.Date.AddDays(7).ToShortTimeString() + "'";
clubAdapt=new SqlDataAdapter(strClubcmdRead,ClubConn);
clubAdapt.Fill(dsClub,"EVNR_tbl");
Label1.Text=myClubNow1.ToString();
Repeater1.DataSource=dsClub;
Repeater1.DataBind();
}
}
"Chris" wrote:
You need to provide more code from the page_load event. In most
cases I've seen like this, it is a scope issue, or a completely
different statement referencing a completly different object than the
one you're assuming is throwing the error.

--
Chris
"I am Sam" <Ia****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...

I have created this DateTime object and instanced it I think
correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,Date Time.Now.Day,DateT
ime.Now.Hour,DateTime.Now.Minute,DateTime.Now.Seco nd);
I keep getting the below error:

Object reference not set to an instance of an object.

I don't know what the problem could be. Can someone help me with
this?
It
is driving me crazy. The stack info is as follows:
NullReferenceException: Object reference not set to an instance of
an
object.]
Sonar3.Controls.WeekendEvents.Page_Load(Object sender, EventArgs e)
in
c:\inetpub\wwwroot\sonar3\controls\weekendevents.a scx.cs:41
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
Help!!!!!!!!!!! Please


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Martin Bless | last post: by
2 posts views Thread by andrew lowe | last post: by
44 posts views Thread by Frank Rizzo | last post: by
8 posts views Thread by Alan Silver | last post: by
9 posts views Thread by Phil B | last post: by
6 posts views Thread by Bryce K. Nielsen | last post: by
5 posts views Thread by iulian.ilea | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.