我不知道为什么此代码给我一个错误。 我想把sql命令放入事务中。 这段代码给了我这个错误。 我不能在此源填充任何东西。 这是错误我得到连接字符串属性尚未初始化
附加信息:(从零开始)指数必须小于参数列表的大小大于或等于零少。
using (SQLiteConnection cn = new SQLiteConnection(string.Format("Data Source={0};")))
{
cn.Open();
using (SQLiteTransaction tr = cn.BeginTransaction())
{
sqlTarget = sqlInsert1 + columnList + ") VALUES (";
object[] sourceVal = new object[nCol];
rdrSourceTable.GetValues(sourceVal);
string strMsg = string.Empty;
int iCol = 0;
foreach (object col in sourceVal)
{
string columnName = rdrSourceTable.GetName(iCol++);
sqlTarget += objDbTarget.ObjectForSql(col, ref strMsg, false, columnName) +
comma;
}
if (strMsg.Length > 0)
{
msg = string.Format(
"The input values are wrong, strMsg = {0}\r\nThe composed sql = {1}",
strMsg, sqlTarget);
if (m_interactive)
{
DialogResult res = MessageBox.Show(msg, GetType().ToString(),
MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (res == DialogResult.Cancel)
{
throw new CopyDbContentsException(msg);
}
}
if (errorCount++ < 5)
{
RadFile.WriteLogMsg("FillTableWithInsertCommands. " + msg +
"\r\n\r\nContinue?");
}
//Skip the insert action because of the error and go to next row.
continue;
}
sqlTarget = sqlTarget.Substring(0, sqlTarget.Length - comma.Length) + ")";
objDbTarget.ExecuteActionQuery(sqlTarget);
iRow++;
int remainder = iRow%250;
if (remainder == 0)
{
WriteStatusLabel(string.Format(
"Copy the rows of table {0}. {1:N0} written.", Name,
iRow));
}
remainder = iRow%nMsgMod;
if (remainder == 0)
{
msg = string.Format("{0:N0} rows of table {1} copied.",
iRow, Name);
RadFile.WriteLogMsg(msg, withHeader: false);
if (nMsgMod < 100000 && iRow == 10*nMsgMod)
{
nMsgMod *= 10;
}
}
tr.Commit();
}
cn.Close();
}
}
msg = string.Format("Table {0} is copied, {1:N0} rows. ", Name, iRow);
if (errorCount > 0)
{
msg += errorCount;
msg += (errorCount == 1) ? " row is" : " rows are";
msg += " skipped because of errors in the input";
}
RadFile.WriteLogMsg(msg, withHeader: false);
}
}
我认为您需要提供一个值,以连接字符串格式中的{0}替换。 –
你不能'string.Format(“Data Source = {0};”)''你没有为'{0}'指定任何东西。 –
这不是所有的代码。它包含超过10000行代码。 – astijn3457