如何在VB.Net中添加月份 [英] How to Add Months in VB.Net
问题描述
亲爱的先生,
我该怎么做: -
我有两个文本框一个用于输入月份和另一个有多少用户想要添加
之后。
输入月份: -
上个月后添加多少次: -
假设用户在第一个文本框中输入1月份并想再增加4个月
在1月份之后在下一个文本框中输入4,我该怎么做,我还在数据库上保存了数据
。
Rgds,
Indranil
Dear Sir,
How can i do this:-
I have two text boxes one for Enter Month and another How many user want to add
after that.
Enter Month :-
How many Add After Above Month:-
Let say if user enter January on first Text Box and want to add 4 more months
after January by enter 4 on next Text Box, how can i do that, i also saved the data
on database.
Rgds,
Indranil
推荐答案
要做的第一件事是将用户输入转换为DateTime - 可能你想使用DateTime.TryParseExact来做然后,您可以使用DateTime.AddMonths方法获取新日期,并将其作为DateTime存储在数据库中。
The first thing to do is convert the users input to a DateTime - probably you want to use DateTime.TryParseExact to do that.
You can then use the DateTime.AddMonths method to get the new date, and store that as a DateTime in the database.
Dim [date] As String = "February"
Dim addMonths As String = "4"
Dim dt As DateTime
If DateTime.TryParseExact([date], "MMMM", CultureInfo.InvariantCulture, DateTimeStyles.None, dt) Then
Dim i As Integer
If Integer.TryParse(addMonths, i) Then
dt = dt.AddMonths(i)
...
End If
End If
谢谢先生您的解决方案,如果您不介意可以告诉我如何将上述记录保存在数据库中
我能做到的那一点'帮助你 - 我有太多不同的数据库系统和表/列组合给你一个简单的答案。
然而,一个使用SQL数据库的简单方法将是:
"Thanks sir for your solution, if you don''t mind can tell me how can save the above record in database"
That bit I can''t help you with - there are too many different database systems and table / column combinations for me to give you a simple answer.
However a simple method using a SQL Database would be along the lines of:
Using con As New SqlConnection(strConnect)
con.Open()
Using com As New SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con)
com.Parameters.AddWithValue("@C1", myValueForColumn1)
com.Parameters.AddWithValue("@C2", myValueForColumn2)
com.ExecuteNonQuery()
End Using
End Using
但是sinc我不知道你的任何细节,你必须自己填写!
But since I do not know any of your details, you will have to fill them in yourself!
这篇关于如何在VB.Net中添加月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!