473,383 Members | 1,829 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,383 software developers and data experts.

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 1971
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Bless | last post by:
Below is what I'm currently using to construct datatime objects from strings. Date and time objects are made up similar. To and from string conversions are frequently needed in SQL neighborhood. ...
9
by: rick cameron | last post by:
TimeZone - the only instance you can get is one representing the local time zone DateTime - cannot represent a time before 00:00:00 1 Jan 1 CE What were they thinking? This is a serious question...
2
by: andrew lowe | last post by:
Hi, Please bear with me on this problem, first I'll give you some background: I have an object that contains a DateTime field which i pass to a webservice public class Foo { public DateTime...
44
by: Frank Rizzo | last post by:
Any ideas?
8
by: Alan Silver | last post by:
Hello, I have a custom control that displays the date and time. I currently have properties for the day, month, year, hour and minute, which have to be set separately. This is inefficient. I...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
5
by: ns21 | last post by:
Our application is windows desktop application. We are using VS.Net 2003, C#, Framework 1.1, SQL 2000. We use webservices to add/update/select objects. We are using XML Serialization. Following is...
6
by: Bryce K. Nielsen | last post by:
I have a Form that has a method that sets a label's text to DateTime.Now.ToString(). Strange thing is, when I call the form twice from the same app, the label shows the old DateTime value. It's...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.