2013-10-30 118 views
0

我得到一個「索引(基於零)必須大於或等於零且小於比參數列表的大小。「在下面的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

你正在做一個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) 
+0

,我希望應該進入佔位符的值是在以下的String.Format的2線.... 這些都是值: 'ExcelSheet', 'GUID',dtResultParentGUID(0),parentObsSetCode,dtResultChildGUID(0),strInsert, '', '',rationaleText,rationaleType – User1

+0

@ Code12 - 我已經做出了嘗試 - 你似乎正在混合意味着用於SQL的東西與用於.NET的東西。如果您使用參數,而不是使用字符串格式構建SQL,那麼您可能會有更好的運氣。 –

相關問題