我有一個函數(上vb.net)來從XMLWebService獲得數據:無法投射型「System.Data.DataView」的目的爲類型「System.Data.IDataReader」
Private Function GetDataSchedule() As DataTable
Dim xTable As Data.DataTable
xTable = xMaster.GetSchedule()
'Bind to DataTable
Dim DT As New System.Data.DataTable
DT.Load(xTable.DefaultView) '--> When I set a breakpoint, the error start from here
Return DT
End Function
然後函數調用GetDataSchedule()
功能:
Public Sub ShowDataSchedule()
Dim DSSchedule As New System.Data.DataSet
DSSchedule.Tables.Add(GetDataSchedule)
End Sub
但是當我執行的代碼,它得到的結果的錯誤消息: Unable to cast object of type 'System.Data.DataView' to type 'System.Data.IDataReader'.
當我剛執行GetDataSchedule()
函數,它返回值,但是當我分別調用函數時,它會出錯。我錯過了什麼嗎?需要你的幫助。謝謝...
嗨,謝謝..它不起作用。我仍然收到了這條消息,我認爲問題不在於回覆null參考,但我不太確定。 – 2012-04-26 02:12:13
對不起,如果我不清楚。我認爲你的問題的解決方案是上面的Copy()方法。空引用檢查是我額外添加的東西。 – 2012-04-26 16:15:32