using (OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["NSBD_SHUJUKU"].ConnectionString))
{
conn.Open();
OracleTransaction trans = conn.BeginTransaction();
try
{
OracleCommand command = new OracleCommand();
command.Connection = conn;
//到此为止跟我们,使用的基本一样
//然后需要添加参数了
command.ArrayBindCount = batchCount;
//注意参数写法:
string insert = string.Format("insert into {0} (spointguid,dsdate{1},srcnote,errnote) values(:spointguid, :dsdate", tableName, fieldNames);
string[] guids = guidList.GetRange(startIndex, batchCount).ToArray();
DateTime[] dates = dateLists.GetRange(startIndex, batchCount).ToArray();
List<string[]> values = new List<string[]>();
for (int i = 0; i < fieldNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length; i++)
{
insert += ",:V" + i.ToString();
values.Add(valueDics.ToArray());
}
insert += ",:srcNote,:errNote)";
command.CommandText = insert;
// 添加参数
OracleParameter guidParam = new OracleParameter("spointguid", OracleDbType.Varchar2);
guidParam.Direction = ParameterDirection.Input;
guidParam.Value = guids;
command.Parameters.Add(guidParam);
OracleParameter dateParam = new OracleParameter("dsdate", OracleDbType.Date);
dateParam.Direction = ParameterDirection.Input;
dateParam.Value = dates;
command.Parameters.Add(dateParam);
for (int i = 0; i < values.Count; i++)
{
OracleParameter valueParam = new OracleParameter("V" + i.ToString(), OracleDbType.Single);
valueParam.Direction = ParameterDirection.Input;
valueParam.Value = values;
command.Parameters.Add(valueParam);
}
OracleParameter srcNoteParam = new OracleParameter("srcnote", OracleDbType.Char);
srcNoteParam.Direction = ParameterDirection.Input;
srcNoteParam.Value = srcNote.ToArray();
command.Parameters.Add(srcNoteParam);
OracleParameter errNoteParam = new OracleParameter("errcnote", OracleDbType.Char);
errNoteParam.Direction = ParameterDirection.Input;
errNoteParam.Value = errNote.ToArray();
command.Parameters.Add(errNoteParam);
correctRows += command.ExecuteNonQuery();
trans.Commit();
conn.Close();
command.Dispose();
}
catch (Exception ex)
{
trans.Rollback();
// throw;
}
finally
{
conn.Close();
}
}
#endregion
}
return correctRows;
}