如何将天数添加到ActiveReports 6和C#上的TextBox

发布于 2025-02-08 21:42:24 字数 389 浏览 2 评论 0原文

我有ActiveReport 6和C#,然后尝试将6天添加到TextBox1值/文本中 这是我尝试的方法,

string text1 = this.textbox1.Text;

我也尝试

string text1 = this.textbox1.Text.ToString();

或字符串text1 = this.textbox1.value

将字符串转换为时间

DateTime date1 = Datime.Parse(text1);

,我继续遇到错误“ Invocation” 如何将文本框数据字符串转换为DateTime?还是如何解决调用错误的目标?

i have activereport 6 and C# and i try to add 6 days to textbox1 value/text
this is what i try

string text1 = this.textbox1.Text;

i also try

string text1 = this.textbox1.Text.ToString();

or string text1 = this.textbox1.Value

convert string to time

DateTime date1 = Datime.Parse(text1);

i keep getting error "target of invocation"
how do i convert textbox data string to datetime? or how do i fix that target of invocation error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2025-02-15 21:42:25

这应该是从文本框中获取文本值的正确方法,因为它已经是字符串。

string text1 = this.Textbox1.Text;

从那里,您应该能够使用标准.NET方法将其转换为日期时间。您做的方式对我来说是正确的,基于 Microsoft's文档。但是,假设您的字符串的格式是dateTime.parse()方法默认理解的格式之一。他们的文档中的示例:

string dateInput = "Jan 1, 2009";
var parsedDate = DateTime.Parse(dateInput);
Console.WriteLine(parsedDate);
// Displays the following output on a system whose culture is en-US:
//       1/1/2009 00:00:00

如果您的字符串与 dateTime.parse默认理解您可能需要使用自定义格式,我相信这可能是您收到的错误的来源。

That should be the correct way to get the text value from the textbox, as it is already a string.

string text1 = this.Textbox1.Text;

From there you should be able to use the standard .NET methods to convert it to a DateTime. The way you did it looks correct to me based on Microsoft's docs. However, that's assuming the format your string is in is one of the formats the DateTime.Parse() method understands by default. Example from their docs:

string dateInput = "Jan 1, 2009";
var parsedDate = DateTime.Parse(dateInput);
Console.WriteLine(parsedDate);
// Displays the following output on a system whose culture is en-US:
//       1/1/2009 00:00:00

If your string is in a different format from one of the handful that DateTime.Parse understands by default you may need to use a custom format, and I believe that could be the source of the error you're receiving.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文