Re: [.NET] Unable to cast object of type
※ 引述《horngsh ()》之銘言:
: ※ 引述《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)
抱歉,再請教一下
關於這部份我已經成功了
現在是
Private Sub PICsMBindingSource_AddingNew(ByVal sender As System.Object, ByVal
e As System.ComponentModel.AddingNewEventArgs) Handles
PICsMBindingSource.AddingNew
Dim Ds As DataSet
Try
Ds = CType(Me.PICsMBindingSource.DataSource, DataSet)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim dt As DataTable = Ds.Tables(PICsM)
Dim rw As DataRow = dt.NewRow
rw("MPartID") = getMPartID()
e.newobject = rw
^^^^^^^^^^^^^^^^
跑這行的時候會有錯誤:
'Objects added to a BindingSource's list must all be of the same type.'
這也是因為來源是dataset而非datatable嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.248.17.41
推
01/17 19:48, , 1F
01/17 19:48, 1F
→
01/18 08:22, , 2F
01/18 08:22, 2F
推
01/18 10:13, , 3F
01/18 10:13, 3F
→
01/18 13:12, , 4F
01/18 13:12, 4F
→
01/18 13:16, , 5F
01/18 13:16, 5F
→
01/18 13:17, , 6F
01/18 13:17, 6F
→
01/18 13:17, , 7F
01/18 13:17, 7F
推
01/18 17:12, , 8F
01/18 17:12, 8F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):