这是我的 VB.Net 项目。在这个阶段,我将数据从 excel 拉到 VS2010。
在这个我有字符串格式的日期 25.10.2013,我想在数据网格中添加这个日期,但它显示“从字符串转换”“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
获取今日功能:
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