我有一个函数(上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