0
Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles btnOpen.Click

' Get the date that the Order Date displays
Dim tmeToday As DateTime = Me.dtpOrderDate.Value        
Dim day As Integer = tmeToday.Day        
Dim month As Integer = tmeToday.Month        
Dim year As Integer = tmeToday.Year        
Dim strMonth() As String = {"Jan", "Feb", "Mar", "Apr", _
                                "May", "Jun", "Jul", "Aug", _
                                "Sep", "Oct", "Nov", "Dec"}        
Dim strFilename As String = CStr(day) & strMonth(month - 1) & _
                  CStr(year) & ".xml"


' If the file exists already, open it        
If File.Exists(strFilename) Then            
' Empty the local data set of any data. This is required if            
' we want the user to be able to open different daily sets of repairs            
Me.dsWorkorders.Clear()

' Open the set of orders placed on the day selected

 dsWorkorders.ReadXml(strFilename)

这是错误(错误出现在最后一行):将字符串转换为 DateTime 时,在将每个变量放入 DateTime 对象之前解析字符串以获取日期

<Workorder>
<CustomerName>Jonathan</CustomerName>
<Address>gdfsg</Address>
<City>ga</City>
<State>gas</State>
<ZipCode>gaf</ZipCode>
<Make>gadfs</Make>
<Model>ags</Model>
<CarYear>gfad</CarYear>
<Problem>gfasd</Problem>
<PartName1>gfdag</PartName1>
<UnitPrice1>123</UnitPrice1>
<Quantity1>4</Quantity1>
<SubTotal1>492</SubTotal1>
<PartName2 />
<UnitPrice2>0</UnitPrice2>
<Quantity2>0</Quantity2>
<SubTotal2>0</SubTotal2>
<PartName3 />
<UnitPrice3>0</UnitPrice3>
<Quantity3>0</Quantity3>
<SubTotal3>0</SubTotal3>
<PartName4 />
<UnitPrice4>0</UnitPrice4>
<Quantity4>0</Quantity4>
<SubTotal4>0</SubTotal4>
<PartName5 />
<UnitPrice5>0</UnitPrice5>
<Quantity5>0</Quantity5>
<SubTotal5>0</SubTotal5>
<JobPerformed1 />
<JobPrice1>0</JobPrice1>
<JobPerformed2 />
<JobPrice2>0</JobPrice2>
<JobPerformed3 />
<JobPrice3>0</JobPrice3>
<JobPerformed4 />
<JobPrice4>0</JobPrice4>
<JobPerformed5 />
<JobPrice5>0</JobPrice5>
<TotalParts>492</TotalParts>
<TotalLabor>0</TotalLabor>
<TaxRate>7.75</TaxRate>
<TaxAmount>0</TaxAmount>
<TotalOrder>492</TotalOrder>
<Recommendations />

有一个示例 xml 文件数据

4

1 回答 1

0

此代码工作正常

Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles btnOpen.Click

' Get the date that the Order Date displays
Dim tmeToday As DateTime = DateTime.Now        
Dim day As Integer = tmeToday.Day        
Dim month As Integer = tmeToday.Month        
Dim year As Integer = tmeToday.Year        
Dim strMonth() As String = {"Jan", "Feb", "Mar", "Apr", _
                                "May", "Jun", "Jul", "Aug", _
                                "Sep", "Oct", "Nov", "Dec"}        
Dim strFilename As String = CStr(day) & strMonth(month - 1) & _
                  CStr(year) & ".xml"

所以....下面的行应该是

CdateDim tmeToday As DateTime =  CDate(Me.dtpOrderDate.Value) 'otherwise its a string cant asign string to a date 

并且假设列出的 dtp 不是实际的 datetimePicker,因为 DateTimePicker.Value 返回一个 DateTime 对象。

于 2013-09-26T22:55:57.130 回答