我正试图弄清如何像以前使用ODP.Net(df.groupby(['column1']).agg({'column2': sum, 'column3': sum,....})
,System.Data.Odbc
)和参数化一样使用ODBC(OracleCommand
)批量插入多条记录查询。
我使用OracleConnection
做过一些研究之后,发现完美的东西是这样的:
odp.net
}
我尝试对odbc使用相同的逻辑,使用string query = @"insert into Customer ( surname, firstName, emailAddress) values
(:surname, :firstName, :emailAddress)";
oracleConnection.Open();
using (var command = oracleConnection.CreateCommand())
{
command.CommandText = query;
command.CommandType = CommandType.Text;
command.BindByName = true;
// In order to use ArrayBinding, the ArrayBindCount property
// of OracleCommand object must be set to the number of records to be inserted
command.ArrayBindCount = bulkData.Count;
command.Parameters.Add(":surname", OracleDbType.Varchar2, bulkData.Select(c => c.Surname).ToArray(), ParameterDirection.Input);
command.Parameters.Add(":firstName", OracleDbType.Varchar2, bulkData.Select(c => c.FirstName).ToArray(), ParameterDirection.Input);
command.Parameters.Add(":emailAddress", OracleDbType.Varchar2, bulkData.Select(c => c.EmailAddress).ToArray(), ParameterDirection.Input);
int result = command.ExecuteNonQuery();
if (result == bulkData.Count)
returnValue = true;
}
,command.Parameters.AddWithValue
和command.Parameters.Add
传递数据,但是仍然难以理解如何管理它。有没有人尝试过?