Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
My winform has multiple dtp's, here is 1 example:
C#
private void btnSave_Click(object sender, EventArgs e){
 //DateTime datetimePicker1 = dtpOpened.Value;
   dtpOpened.Value = DateTime.Today;}

BLL layer:
C#
public DateTime OpenedDate 
		{ get; set; }
private MainCaseBL(DataRow dr) : base(dr)
{OpenedDate = dr.Field<DateTime>("OpenedDate");}

DAL layer:
C#
public static void Save(DateTime openedDate,...)
{Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetStoredProcCommand("Case_Save");
db.AddInParameter(dbCommand, "@OpenedDate", DbType.DateTime);
db.SetParameterValue(dbCommand, "@OpenedDate", openedDate);}


While debugging Save, I get value back in form of 1/1/0001 12:00:00 AM, not today's date value entered by user. What am I doing wrong? Or not doing? Any help is appreciated, thanks in advance
Posted
Updated 3-Mar-15 5:34am
v5
Comments
InbarBarkai 24-Feb-15 0:33am    
1. Where exactly are you checking for the value? dr.Field?
2. Where do you initialize or update the DataRow?

A little more code will be mush helpful for the understanding of the situation.
Tejas Vaishnav 24-Feb-15 1:21am    
please do one thing, as you mention while you are debugging your code you always get default date. so again debug your application and check what is parameter value is set in your save method of DAL, please check that you are passing correct value to your store procedure to save it. and also check your store procedure that it is updating correct value or not?
Sinisa Hajnal 24-Feb-15 2:20am    
A bit more of the btnSave code would help to see how are you using the data.
Naveen Kumar Tiwari 24-Feb-15 2:28am    
what's the datatype of date field in your database table?

The save code is correct.. Please let me know code for retrieving the database record.. which contains OpenedDate field.
 
Share this answer
 
added instance of my BL class to complete dtp syntax. DTP value saves correctly now. Thank you.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Apr-15 19:35pm    
Sorry, this is not an answer. Such posts are considered as abuse. You could simply informs the readers using comments. I would advise to remove this post, to avoid abuse reports.
—SA
I was not using the class instance for my datetime picker. I only had a basic dtp.date that was not binding to my BLL objects.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Apr-15 19:34pm    
Sorry, this is not an answer. Such posts are considered as abuse. You could simply informs the readers about that using comments. I would advise to remove this post, to avoid abuse reports.
—SA
Sergey Alexandrovich Kryukov 29-Apr-15 19:35pm    
...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900