I have two date pickers in my form: one for start date and one for endate. When I debug the program I realise that the start date is captured correctly, but the end date comes back as '1/1/0001' 12:00:00 AM. What would be the problem?
The date that you are recieving for your EndDate is the default value for a DateTime object. If the field on your form was blank and you would like to use null for the value rather than the '1/1/0001 12:00:00 AM', you may want to consider using a nullable
DateTime :
//Normal Date Time
DateTime StartDate;
//Nullable Date Time
DateTime? EndDate;
I would make sure that you are setting the value properly and don't have any possible spelling errors that could cause the value to be mapped incorrectly.
As oned_gk and I had mentioned before, definately check your values and property names to ensure they match and there aren't any misspelling issues. Could you post some of your markup? It might help us troubleshooting your issue.
protected void Button1_Click(object sender, EventArgs e)
{
/*TODO: Retrieve eBiz rep ID, period start date and period end date in question*/
int eBizCSRId = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
DateTime startDate = Convert.ToDateTime(TextBox1.Text.ToString());
DateTime endDate = Convert.ToDateTime(TextBox2.Text);
/*Run query based on the data entered*/
PCMSdatasetTableAdapters.ContactMethodTableAdapter contact = new PCMSdatasetTableAdapters.ContactMethodTableAdapter();
/*Bind to grid view for display*/
GridView1.DataSource = contact.RegisteredCustomerperRep(eBizCSRId, startDate, endDate);
//GridView1.DataSource = contact.RegisteredCustomerperRep2(eBizCSRId, startDate, endDate);
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
/*TODO: Retrieve eBiz rep ID, period start date and period end date in question*/
int eBizCSRId = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
DateTime startDate = Convert.ToDateTime(TextBox1.Text.ToString());
DateTime endDate = Convert.ToDateTime(TextBox2.Text.ToString());
/*Run query based on the data entered*/
PCMSdatasetTableAdapters.ContactMethodTableAdapter contact = new PCMSdatasetTableAdapters.ContactMethodTableAdapter();
/*Bind to grid view for display*/
GridView1.DataSource = contact.RegisteredCustomerperRep(eBizCSRId, startDate, endDate);
//GridView1.DataSource = contact.RegisteredCustomerperRep2(eBizCSRId, startDate, endDate);
GridView1.DataBind();
}
Ok I did that. I had also did a repair of my Visual Web Developer and I got the correct end date. Thanks.
However after I click the submit button to display my grid view, I got the error "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." I have no constraints on my database currently, only
the necessary primary keys in each of the tables.
check datetime value using label. Label1.text = startdate.ToString("dd MMM yyyy"). If you get wrong value maybe format problem, but if you get right value the problem i think from contact.RegisteredCustomerperRep function.
aussiejmasp
Member
19 Points
110 Posts
One of my date pickers returning 1/1/0001
Jan 16, 2013 06:39 PM|LINK
I have two date pickers in my form: one for start date and one for endate. When I debug the program I realise that the start date is captured correctly, but the end date comes back as '1/1/0001' 12:00:00 AM. What would be the problem?
Rion William...
All-Star
27876 Points
4611 Posts
Re: One of my date pickers returning 1/1/0001
Jan 16, 2013 07:08 PM|LINK
The date that you are recieving for your EndDate is the default value for a DateTime object. If the field on your form was blank and you would like to use null for the value rather than the '1/1/0001 12:00:00 AM', you may want to consider using a nullable DateTime :
I would make sure that you are setting the value properly and don't have any possible spelling errors that could cause the value to be mapped incorrectly.
aussiejmasp
Member
19 Points
110 Posts
Re: One of my date pickers returning 1/1/0001
Jan 16, 2013 11:44 PM|LINK
But I do not want to use the null value. I want the value that I select in the date picker
oned_gk
All-Star
31766 Points
6492 Posts
Re: One of my date pickers returning 1/1/0001
Jan 17, 2013 12:00 AM|LINK
Maybe
(1) wrong format dd/MM/yyyy or MM/dd/yyyy
(2) wrong property, usualy is selecteddate
Rion William...
All-Star
27876 Points
4611 Posts
Re: One of my date pickers returning 1/1/0001
Jan 17, 2013 12:52 AM|LINK
aussiejmasp
Member
19 Points
110 Posts
Re: One of my date pickers returning 1/1/0001
Jan 17, 2013 08:49 AM|LINK
Here is a snippet of my code below:
<div class="style4"> <span class="style2">Registration Period:</span><br /> <em>Start Date:</em> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:CalendarExtender ID="Cal1" runat="server" PopupButtonID="txt1" TargetControlID="TextBox1" /> <br /> <em>End Date:</em> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:CalendarExtender ID="Cal2" runat="server" PopupButtonID="txt2" TargetControlID="TextBox2" /> <br /> <asp:Button runat='server' Text='Submit' ID="Button1" onclick="Button1_Click"/> </div>Code Behind:
protected void Button1_Click(object sender, EventArgs e) { /*TODO: Retrieve eBiz rep ID, period start date and period end date in question*/ int eBizCSRId = Convert.ToInt32(DropDownList1.SelectedValue.ToString()); DateTime startDate = Convert.ToDateTime(TextBox1.Text.ToString()); DateTime endDate = Convert.ToDateTime(TextBox2.Text); /*Run query based on the data entered*/ PCMSdatasetTableAdapters.ContactMethodTableAdapter contact = new PCMSdatasetTableAdapters.ContactMethodTableAdapter(); /*Bind to grid view for display*/ GridView1.DataSource = contact.RegisteredCustomerperRep(eBizCSRId, startDate, endDate); //GridView1.DataSource = contact.RegisteredCustomerperRep2(eBizCSRId, startDate, endDate); GridView1.DataBind(); }Rion William...
All-Star
27876 Points
4611 Posts
Re: One of my date pickers returning 1/1/0001
Jan 17, 2013 11:49 AM|LINK
You are missing a .ToString() when reading your endDate value :
Here's a full example :
protected void Button1_Click(object sender, EventArgs e) { /*TODO: Retrieve eBiz rep ID, period start date and period end date in question*/ int eBizCSRId = Convert.ToInt32(DropDownList1.SelectedValue.ToString()); DateTime startDate = Convert.ToDateTime(TextBox1.Text.ToString()); DateTime endDate = Convert.ToDateTime(TextBox2.Text.ToString()); /*Run query based on the data entered*/ PCMSdatasetTableAdapters.ContactMethodTableAdapter contact = new PCMSdatasetTableAdapters.ContactMethodTableAdapter(); /*Bind to grid view for display*/ GridView1.DataSource = contact.RegisteredCustomerperRep(eBizCSRId, startDate, endDate); //GridView1.DataSource = contact.RegisteredCustomerperRep2(eBizCSRId, startDate, endDate); GridView1.DataBind(); }aussiejmasp
Member
19 Points
110 Posts
Re: One of my date pickers returning 1/1/0001
Jan 19, 2013 06:15 PM|LINK
Ok I did that. I had also did a repair of my Visual Web Developer and I got the correct end date. Thanks.
However after I click the submit button to display my grid view, I got the error "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." I have no constraints on my database currently, only the necessary primary keys in each of the tables.
Rion William...
All-Star
27876 Points
4611 Posts
Re: One of my date pickers returning 1/1/0001
Jan 19, 2013 09:47 PM|LINK
Could any of the fields that you are updating possibly be placing a null value in a non-null field? Or any possible primary key conflicts?
The following Stack Overflow thread discusses the same issue, hopefully it can provide some assistance :
Failed to Enable Constraints Problem
oned_gk
All-Star
31766 Points
6492 Posts
Re: One of my date pickers returning 1/1/0001
Jan 19, 2013 11:46 PM|LINK