无法将'system.int32'类型的对象强制转换为'system.int32 []'

时间:2013-04-24 09:45:19

标签: vb.net type-conversion

我在第四行得到了上述错误。我如何(假设我必须)将值转换为双方都具有相同的数据类型?

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 个答案:

答案 0 :(得分:1)

您需要将dataRow中的值转换为int,string等值,然后再将其赋值给另一个类型为int的变量

答案 1 :(得分: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"})