DateTime Instance problem

G

Guest

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

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.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.ascx.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
 
C

Chris

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.
 
G

Guest

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.
 
G

Guest

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,DateTime.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 said:
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 said:
I have created this DateTime object and instanced it I think correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.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.ascx.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
 
M

Matt Berther

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,DateTime.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 said:
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 have created this DateTime object and instanced it I think
correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,DateT
ime.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.ascx.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
 
G

Guest

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 said:
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,DateTime.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 said:
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 have created this DateTime object and instanced it I think
correctly

DateTime myClubNow1=new
DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,DateT
ime.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.ascx.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
 

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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top