0

我得到一个“索引(从零开始)必须大于或等于零且小于参数列表的大小。” 以下插入命令中的错误(请参阅插入 sql 命令).. 我已经更正了参数列表,并且我指的是正确的表....

 Dim dtResultParentGUID As DataTable

                'Get the GUID for the parent ObsSetCode
                Dim sbSql As New System.Text.StringBuilder()
                sbSql.Append("DECLARE @parentObsSetGUID uniqueidentifier ")
                sbSql.Append("SELECT GUID ")
                sbSql.Append("FROM {0} ")
                sbSql.Append("WHERE {1} = '{2}';")

                dtResultParentGUID = AicDatabase.ExecuteSqlReturnTable(String.Format(sbSql.ToString(), aicObsSet, pTablePrimaryKeyName, parentObsSetCode))


                Dim dtResultChildGUID As DataTable

                'Get the GUID for the child ObsSetCode
                Dim sbSql1 As New System.Text.StringBuilder()
                sbSql1.Append("DECLARE @childObsSetGUID uniqueidentifier ")
                sbSql1.Append("SELECT  GUID ")
                sbSql1.Append("FROM {0} ")
                sbSql1.Append("WHERE {1} = '{2}';")


                dtResultChildGUID = AicDatabase.ExecuteSqlReturnTable(String.Format(sbSql.ToString(), aicObsSet, pTablePrimaryKeyName, strInsert))

                strSql.Append("DECLARE @cur_date_time datetime; ")
                strSql.Append("SELECT @cur_date_time = getdate(); ")
                strSql.Append("WAITFOR DELAY '00:00:00.100'; ")

                strSql.Append("INSERT INTO aic_obs_set_obs_set_obs_item_xref_chg (ModifiedBy, ContentGUID, ParentObsSetGUID, ParentObsSetCode,")
                strSql.Append("ChildObsSetGUID, ChildObsSetCode, ChildObsItemGUID, ChildObsItemCode, RationaleText, RationaleFreeText")
                strSql.Append(String.Format("SELECT '{0}', '{1}', '{2}', '{3}','{4}', '{5}','{6}', '{7}','{8}', '{9}',"))
                strSql.Append("'ExcelSheet', 'GUID', dtResultParentGUID(0), parentObsSetCode, dtResultChildGUID(0), strInsert,")
                strSql.Append("'','', rationaleText, rationaleType")

                latLog.Operation = sbSql.ToString
                latLog.WriteLog()

                latLog.Operation = sbSql1.ToString
                latLog.WriteLog()
4

1 回答 1

0

你正在做一个String.Format但没有提供任何值来代替它:

String.Format("SELECT '{0}', '{1}', '{2}', '{3}','{4}', '{5}','{6}', '{7}','{8}', '{9}',"))

(这是Append代码底部的最后一个第二条调用)

你期望在这些占位符中加入什么?


然后根据评论,它应该是这样的:

strSql.Append(String.Format("SELECT '{0}', '{1}', '{2}', '{3}','{4}', '{5}','{6}', '{7}','{8}', '{9}'," _
      "ExcelSheet", "GUID", dtResultParentGUID(0), parentObsSetCode, dtResultChildGUID(0), strInsert, _
      "","", rationaleText, rationaleType)
于 2013-10-30T15:36:57.933 回答