Home > Net >  How to assign a date variable from form1 to form2 in datetimepicker
How to assign a date variable from form1 to form2 in datetimepicker

Time:08-01

In Section 28 of my source code I am assigning, the database field of date (car_completiondate) to a variable mcompdate and also to label4.Text. I want to use mcompdate or label4.Text in the second form, please advise how to?

// 28
// var mcompdate = (DateTime)reader1["car_completiondate"];
// label4.Text = (String.Format("{0:yyyy-mm-dd}", Convert.ToDateTime(reader1[28]).ToShortDateString()));
label4.Text = (Convert.ToDateTime(reader1[28]).ToString("yyyy-MM-dd"));
DateTime mcompdate = DateTime.Parse(label4.Text);
                
// DateTime mcompdate = DateTime.ParseExact(label4.Text, "yyyy-MM-dd", null);      

CodePudding user response:

Well the easiest way is to make a field in one Form and access it in the other Form. For example

Field in second Form:

public DateTime date { private get; set; }

Now in first Form you just have to set the value of the date field form2_name.setValue(mcompdate) and then in the second form you can use however you like. If you want to performs more operations than you can also use a public method just as explained.

CodePudding user response:

You can create a global class and in this class create a global variable to assign this values. Then you can access in all forms.

  • Related