0
這是我的VB.Net項目。在這個階段,我將數據從excel提取到VS2010。將字符串轉換爲日期
在這裏我有日期字符串格式25.10.2013,我想添加這個日期在datagrid,但它顯示「從字符串轉換」「25.10.2013」鍵入'日期'是無效的「錯誤。
請同時檢查以下值編碼(功能&雖然),並提供我的解決方案來解決這個
If DialogResult = Windows.Forms.DialogResult.OK Then
Try
Dim objreader As New System.IO.StreamReader(OpenDLG.FileName)
linecount = 0
dupord = 0
nooford = 0
While Not objreader.EndOfStream
fallout = objreader.ReadLine
If linecount >= 0 Then
If fallout = "" Then
Exit While
End If
' Dim tmpArray() As String = Regex.Split(Trim(velocityfallout), " ")
Dim tmpArray() As String = Regex.Split(Trim(fallout), ",")
If tmpArray(0) = "" Then
Exit While
End If
pono = tmpArray(0)
issue = tmpArray(1)
falldate = getToday(tmpArray(3))
ftype = "Velocity"
checkfallout("Velocity", "", "", falldate, "", pono, "", issue, "")
nooford = nooford + 1
End If
linecount += 1
End While
GetToday功能:
Function getToday(ByVal dateStr As Date) As String
Dim dateStrRet As String
dateStrRet = CStr(DatePart("yyyy", dateStr)) & "-"
If DatePart("m", dateStr) < 10 Then
dateStrRet = dateStrRet & "0" & CStr(DatePart("m", dateStr)) & "-"
Else
dateStrRet = dateStrRet & CStr(DatePart("m", dateStr)) & "-"
End If
If DatePart("d", dateStr) < 10 Then
dateStrRet = dateStrRet & "0" & CStr(DatePart("d", dateStr))
Else
dateStrRet = dateStrRet & CStr(DatePart("d", dateStr))
End If
Return dateStrRet
End Function