Reputation: 13216
I'm trying to write a value to CurrentRent.Text and NextRent.Text (both labels on my form and keep getting the following error messages:
Error 1 'System.DateTime' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)
Error 2 'System.DateTime' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)
How can I resolve it? This is my code so far:
public Form1()
{
InitializeComponent();
CurrentDate.Text = "Today's Date: " + DateTime.Now;
DateTime CurrentRent;
DateTime NextRent;
DateTime today = DateTime.Now;
if (today.DayOfWeek == DayOfWeek.Wednesday)
{
CurrentRent.Text = "Current Rent Date: " + today.AddDays(-7);
NextRent.Text = "Next Rent Date: "+ today.AddDays(7);
}
}
Upvotes: 0
Views: 3908
Reputation: 564641
You declared a local variable that "hides" your labels:
DateTime CurrentRent;
Just comment that out:
// Don't include this - it hides your label:
// DateTime CurrentRent;
Since that is declared locally, you're trying to set the "Text" property of the local CurrentRent variable, not your label.
Upvotes: 1
Reputation: 203827
Well, the error seems pretty clear to me. You're trying to set the text of a DateTime
. DateTime
doesn't have a Text
property. If you want to be setting the text of some label, then set the text of a label, rather than the text of a DateTime
.
Upvotes: 4