2013-04-24 120 views
1

我在第四行出現上述錯誤。我如何(假設我必須)將值轉換爲雙方都具有相同的數據類型?無法投射'system.int32'類型的對象來鍵入'system.int32 []'

dsOrderList = objResult.ds 
     For Each drow As DataRow In dsOrderList.Tables(0).Rows 
      Dim objOrder As New Orders 
      objOrder.OrderID = drow("OrderID") 
      objOrder.CustomerID = drow("CustomerID") 
      objOrder.EmployeeID = drow("EmployeeID") 
+2

是它的財產Orders.OrderID int數組? – Steve 2013-04-24 09:59:16

+0

很好的抓住史蒂夫......可能是這個問題,雖然一些鑄造也可能是好的。 – 2013-04-24 10:01:10

+0

是的............ – adityawho 2013-04-24 10:04:40

回答

1

我認爲你是字符串值到數組的整,必須有一個陣列或提供數組的元素

dsOrderList = objResult.ds 
    For Each drow As DataRow In dsOrderList.Tables(0).Rows 
     Dim objOrder As New Orders 
     objOrder.OrderID(0) = drow("OrderID") '0 is Element of Order ID 
     objOrder.CustomerID = drow("CustomerID") 
     objOrder.EmployeeID = drow("EmployeeID") 

dsOrderList = objResult.ds 
    For Each drow As DataRow In dsOrderList.Tables(0).Rows 
     Dim objOrder As New Orders 
     objOrder.OrderID = {drow("OrderID")} 
     objOrder.CustomerID = drow("CustomerID") 
     objOrder.EmployeeID = drow("EmployeeID") 

更新

如果objOrder.OrderID的元素是什麼,然後使用

objOrder.OrderID = new int() {drow{"OrderID"}) 
1

您需要的值從數據行轉換爲int,字符串等將其分配給另一個變量,其類型爲前值大概詮釋

+0

喜歡如何? .... – adityawho 2013-04-24 09:53:34

+0

喜歡做類型轉換... http://www.codeproject.com/Articles/5044/Cheat-Sheet-Casting-in-VB-NET-and-C,但看到史蒂夫對你的問題的評論,這可能是你的問題的原因... – 2013-04-24 10:02:44

+0

其數組.. ..(如在多個值) – adityawho 2013-04-24 10:08:55

相關問題