Image 1
当我尝试添加新帐单时会出现问题。
消息说:
从字符串转换" 4/20 / 2017"键入' date'无效。在Microsoft.VisualBasic.CompilerServices.conversions.ToDate(字符串值)
第1054行中的问题Dim duedate
为String = DateAdd("d", +10, CDate(GetLastDayOfMonth))
和第1102行<pre>set_CutoffDates
Private Sub set_CutoffDates()
sqlstring = "SELECT " &
" * " &
" FROM " &
" tblBillingProcess "
read_record(sqlstring, "tblBillingProcess")
txtDate.Text = Date.Now.ToShortDateString
' check if first billing get the last month's dates
If ds.Tables("tblBillingProcess").Rows.Count = 0 Then
'Dim datenow As Date = Now.Date
'Dim Prev_Month As String = Month(DateAdd("m", -1, datenow))
'Dim Prev_Year As String = Year(DateAdd("m", -1, datenow))
'Dim firstdayprevmonth As String = Prev_Month & "/01/" & Prev_Year
'Dim GetLastDayOfMonth As String = DateSerial(CInt(Prev_Year), CInt(Prev_Month) + 1, 0)
'txtFrom.Text = firstdayprevmonth
'txtTo.Text = GetLastDayOfMonth
Dim datenow As Date = Now.Date
Dim Prev_Month As String = Month(DateAdd("m", -1, datenow))
Dim Prev_Year As String = Year(DateAdd("m", -1, datenow))
'Dim firstdayprevmonth As String = Prev_Month & "/01/" & Prev_Year
Dim periodFrom As String = Prev_Month & "/21/" & Prev_Year
Dim NOW_Month As String = Month(datenow)
Dim NOW_Year As String = Year(datenow)
Dim firstdayofmonth As String = NOW_Month & "/01/" & NOW_Year
Dim GetLastDayOfMonth As String = NOW_Month & "/20/" & NOW_Year
'Dim duedate As String = DateAdd("d", +10, datenow)
Dim duedate As String = DateAdd("d", +10, GetLastDayOfMonth)
txtFrom.Text = periodFrom
txtTo.Text = GetLastDayOfMonth
txtDueDate.Text = duedate
Else
Dim datenow As Date
'sqlstring = "SELECT " & _
' " MAX(Periodfrom) as Periodfrom " & _
' " FROM " & _
' " tblBillingProcess "
sqlstring = "SELECT " &
" MAX(Periodto) as Periodfrom " &
" FROM " &
" tblBillingProcess "
read_record(sqlstring, "tblBillingProcessdate")
datenow = CDate(ds.Tables("tblBillingProcessdate").Rows(0).Item("Periodfrom").ToString)
'Dim Prev_Month As String = Month(DateAdd("m", -1, datenow))
'Dim Prev_Year As String = Year(DateAdd("m", -1, datenow))
Dim Prev_Month As String = Month(datenow)
Dim Prev_Year As String = Year(datenow)
Dim periodFrom As String = Prev_Month & "/21/" & Prev_Year
Dim NOW_Month As String = Month(DateAdd("m", +1, datenow))
Dim NOW_Year As String = Year(DateAdd("m", -1, datenow))
Dim firstdayofmonth As String = NOW_Month & "/01/" & NOW_Year
Dim GetLastDayOfMonth As String = NOW_Month & "/20/" & NOW_Year
Dim duedate As String = DateAdd("d", +10, CDate(GetLastDayOfMonth))
txtFrom.Text = periodFrom
txtTo.Text = GetLastDayOfMonth
txtDueDate.Text = duedate
End If
End Sub
Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
Try
If btnadd.Text = "&Add" Then
If Get_PendingPresentReading() = True Then
MsgBox("You must complete all present reading before creating new billing process ",
MsgBoxStyle.Exclamation, Text)
Exit Sub
End If
reset_controls()
dgProcess.Rows.Clear()
txtBillingNo.Text = String.Empty
txtFrom.Text = String.Empty
txtTo.Text = String.Empty
txtDueDate.Text = String.Empty
txtDate.Text = String.Empty
generate_billingNO()
load_data()
set_CutoffDates()
btnadd.Text = "&Save"
btnedit.Enabled = False
btncancel.Enabled = True
btnMain.Enabled = False
btnFind.Enabled = False
Else
If MsgBox("Are you sure to save this transaction ",
MsgBoxStyle.Question + MsgBoxStyle.YesNo, Me.Text) = MsgBoxResult.No Then
Exit Sub
End If
答案 0 :(得分:0)
本月的最后一天,这是计算:
DateTime now = DateTime.Today;
var lastDate = new DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month);
然后显示它。它将使用您的默认文化。
txtDueDate.Text = lastDate.ToShortDateString();
如果你想要MM / dd / yyyy而不管它是否是一台en-US计算机,请使用:
txtDueDate.Text = lastDate.ToString("MM/dd/yyyy");