我得到一个“索引(基于零)必须大于或等于零且小于参数列表的大小。”以下Insert命令中的错误(请参阅insert 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()
答案 0 :(得分: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)