2015-10-06 75 views
0

我在c#中有一些代碼是從vb.net轉換而來的。我在aspx頁面的代碼隱藏頁面上收到此錯誤。一個錯誤的讀取無法對c#中的'dtInventory_v10_r1'類型錯誤表達式應用索引

無法適用索引,以類型的表達式「dtInventory_v10_r1」

,我從Visual Studio接收讀取該然而

參數丟失

錯誤

本文引用的代碼行如下:

objInv = objMan.GetInventoryObject(mInventory_ID, , , true); 

的GetInventoryObject是用VB寫,看起來像這樣

Public Function GetInventoryObject(ByVal vInventory_ID As Integer, _ 
    Optional ByVal vVIN As String = "", _ 
    Optional ByVal vSelectedTrim As String = "", _ 
    Optional ByVal vIncludeDetail As Boolean = False, _ 
    Optional ByVal vIncludeValuations As Boolean = False, _ 
    Optional ByVal vIncludeEquipment As Boolean = False, _ 
    Optional ByVal vIncludeTitle As Boolean = False, _ 
    Optional ByVal vIncludeBuyersGuide As Boolean = False, _ 
    Optional ByVal vIncludeImages As Boolean = False, _ 
    Optional ByVal vIncludeFinance As Boolean = False, _ 
    Optional ByVal vIncludeExpenses As Boolean = False, _ 
    Optional ByVal vIncludeTransactions As Boolean = False, _ 
    Optional ByVal vIncludeInternetMarketing As Boolean = False, _ 
    Optional ByVal vIncludeFlags As Boolean = False, _ 
    Optional ByVal vIncludeSupportingFiles As Boolean = False, _ 
    Optional ByVal vYearModel As Integer = 0, _ 
    Optional ByVal vMake As String = "", _ 
    Optional ByVal vModel As String = "", _ 
    Optional ByVal vBodyStyle As String = "", _ 
    Optional ByVal vExtTrim As String = "", _ 
    Optional ByVal vExtColor As String = "", _ 
    Optional ByVal vIntColor As String = "", _ 
    Optional ByVal vTransmission As String = "", _ 
    Optional ByVal vDriveType As String = "", _ 
    Optional ByVal vEngine As String = "", _ 
    Optional ByVal vWeight As Integer = 0, _ 
    Optional ByVal vFuelType As String = "", _ 
    Optional ByVal vLot_ID As Integer = 0 
    ) As Inventory 

    Dim strParameters As String = "" 
    Dim dsTempDataSet As DataSet 
    Dim strXML As String = "" 

    If vLot_ID = 0 Then 
     'if an autosave occurs and a lot is not enterd 
     'pass in the uses branch 
     vLot_ID = mobjSecurity.Branch_ID 
    End If 

    strParameters = "@SessionGUID='" & mobjSecurity.SecuritySession & "', " 
    strParameters &= "@Inst_ID=" & mobjSecurity.Inst_ID.ToString & ", " 
    strParameters += "@Inventory_ID=" & vInventory_ID.ToString & ", " 
    strParameters += "@VIN='" & vVIN.ToString & "', " 
    strParameters += "@IncludeDetail=" & mobjFormat.FormatBooleanToInteger(vIncludeDetail) & ", " 
    strParameters += "@IncludeValuations=" & mobjFormat.FormatBooleanToInteger(vIncludeValuations) & ", " 
    strParameters += "@IncludeEquipment=" & mobjFormat.FormatBooleanToInteger(vIncludeEquipment) & "," 
    strParameters += "@IncludeTitle=" & mobjFormat.FormatBooleanToInteger(vIncludeTitle) & ", " 
    strParameters += "@IncludeBuyersGuide=" & mobjFormat.FormatBooleanToInteger(vIncludeBuyersGuide) & ", " 
    strParameters += "@IncludeImages=" & mobjFormat.FormatBooleanToInteger(vIncludeImages) & ", " 
    strParameters += "@IncludeFinance=" & mobjFormat.FormatBooleanToInteger(vIncludeFinance) & ", " 
    strParameters += "@IncludeExpenses=" & mobjFormat.FormatBooleanToInteger(vIncludeExpenses) & ", " 
    strParameters += "@IncludeTransactions=" & mobjFormat.FormatBooleanToInteger(vIncludeTransactions) & ", " 
    strParameters += "@IncludeInternetMarketing=" & mobjFormat.FormatBooleanToInteger(vIncludeInternetMarketing) & ", " 
    strParameters += "@IncludeFlags=" & mobjFormat.FormatBooleanToInteger(vIncludeFlags) & ", " 
    strParameters += "@IncludeSupportingFiles=" & mobjFormat.FormatBooleanToInteger(vIncludeSupportingFiles) & ", " 
    strParameters += "@YearModel=" & vYearModel.ToString & ", " 
    strParameters += "@Make='" & vMake.ToString & "', " 
    strParameters += "@Model='" & vModel.ToString & "', " 
    strParameters += "@BodyStyle='" & vBodyStyle.ToString & "', " 
    strParameters += "@ExtTrim='" & vExtTrim.ToString & "', " 
    strParameters += "@ExtColor='" & vExtColor.ToString & "', " 
    strParameters += "@IntColor='" & vIntColor.ToString & "', " 
    strParameters += "@Transmission='" & vTransmission.ToString & "', " 
    strParameters += "@DriveType='" & vDriveType.ToString & "', " 
    strParameters += "@Engine='" & vEngine.ToString & "', " 
    strParameters += "@Weight=" & vWeight.ToString & ", " 
    strParameters += "@FuelType='" & vFuelType.ToString & "', " 
    strParameters += "@Lot_ID=" & vLot_ID.ToString & " " 

    dsTempDataSet = Fetch("pr_Inventory_v10_FetchObject_r1", strParameters, mobjSecurity.SQLDatabase) 

    Dim dsComplete As New DataSet 
    Dim objExport As New dtDataTools_v10_r1.ExportData 

    Dim iTable As Integer = 0 
    Dim sDataTableName As String = "" 
    Dim sRelatedTableName As String = "" 
    Dim sRelatedFieldName As String = "" 

    '-- Loop all returned tables 
    For iTable = 0 To dsTempDataSet.Tables.Count - 1 
     If sDataTableName = "" Then 
      '-- Make sure we have rows 
      If dsTempDataSet.Tables(iTable).Rows.Count > 0 Then 
       '-- Read first column... 
       If dsTempDataSet.Tables(iTable).Columns(0).ColumnName.ToLower = "datatablename" Then 
        '-- Get table info 
        sDataTableName = dsTempDataSet.Tables(iTable).Rows(0).Item("datatablename") 
        sRelatedTableName = dsTempDataSet.Tables(iTable).Rows(0).Item("RelatedTableName") 
        sRelatedFieldName = dsTempDataSet.Tables(iTable).Rows(0).Item("RelatedFieldName") 
       End If 
      End If 
     Else 
      '-- Name and store the table 
      dsTempDataSet.Tables(iTable).TableName = sDataTableName 
      dsComplete.Tables.Add(dsTempDataSet.Tables(iTable).Copy) 
      Try 

       '-- Add Relationship? 
       If sRelatedTableName.Trim <> "" Then 
        With dsComplete 
         .Relations.Add("rel_" & sDataTableName, _ 
          .Tables(sRelatedTableName).Columns(sRelatedFieldName), _ 
          .Tables(sDataTableName).Columns(sRelatedFieldName)) 
        End With 
       End If 
      Catch ex As Exception 

      End Try 

      sDataTableName = "" '-- Reset 
      sRelatedTableName = "" 
      sRelatedFieldName = "" 

     End If 

    Next 

    '-- Generate and strip the XML 
    strXML = objExport.ConvertDatasetToXML(dsComplete.Copy, "dealtrace", MappingType.Attribute, 1) 
    '-- Load XML into Report object 
    Return LoadInventory_XML(strXML) 

End Function 

的mInventory_ID是一個i​​nt變量,並聲明如下

protected Int32 mInventory_ID = 0; 

我不知道如何解決錯誤我正在嘗試將括號改爲方括號無濟於事。我已經嘗試在函數中爲剩餘的聲明添加額外的逗號,但也產生了相同的錯誤。

是否有什麼可能會導致此錯誤,以及如何解決這個

任何建議,謝謝你在前進

回答

2

這些都是可選的參數,並應符合以下語法

objInv = objMan.GetInventoryObject(vVIN=mInventory_ID, vIncludeValuations=true); 
被稱爲

基本上你明確地命名參數的默認值,你想重寫。與, ,跳過param實際上是不正確的語法。

+0

這似乎工作,但最後一條語句「vIncludeValuations = true」引發此錯誤「參數類型'布爾'不可分配給參數類型'字符串'」我應該把單引號繞真? – MaximusPrime

+0

我通過將Convert.ToString添加到vIncludeValuations來修復了其餘的錯誤 – MaximusPrime

相關問題