Re: [.NET] Unable to cast object of type

看板Visual_Basic作者時間15年前 (2011/01/15 19:27), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串2/3 (看更多)
※ 引述《mindscold (喵)》之銘言: : Dim Table As DataTable = DirectCast(Me.myBindingSource.DataSource, DataTable) : 並且出現以下的錯誤訊息: : "Unable to cast object of type 'PICData.PICSettingDataSet' to type : 'System.Data.DataTable' : 請問為什麼datasource也是table卻不能轉換成datatable? : 該怎麼改才是對的呢?謝謝 Try Dim ds as DataSet = CType(Me.myBindingSource.DataSource, DataSet) Catch ex As Exception MsgBox(ex.Message) End Try Dim dt1 as DataTable = ds.Tables(0) -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 112.104.148.39

01/15 19:29, , 1F
忘了Scope限制,請把ds改放在Try 上方,如Dim ds as DataSet
01/15 19:29, 1F

01/15 19:29, , 2F
然後Try下面用ds = CType(....)
01/15 19:29, 2F

01/17 08:23, , 3F
感謝,我馬上試試
01/17 08:23, 3F
文章代碼(AID): #1DCOIO8K (Visual_Basic)
文章代碼(AID): #1DCOIO8K (Visual_Basic)