问题描述
我想使用数组绑定将批量数据插入到 oracle 表中。
操作代码,抛出异常。
IList<DetailsDto> detailsListDto = new List<DetailsDto>();
query = @"INSERT INTO t115_allocdetails (c115_storeno,c115_itemno,c115_id) VALUES (:c115_storeno,:c115_itemno,:c115_id)";
long[] ids = new long[allocationDetails.Count];
long[] stores = new long[allocationDetails.Count];
string[] itemnumbers = new string[allocationDetails.Count];
for (int j = 0; j < allocationDetails.Count; j++)
{
ids[j] = Convert.ToInt64(allocationDetails[j].Id);
stores[j] = Convert.ToInt64(allocationDetails[j].Item.StoreNumber);
itemnumbers[j] = Convert.ToString(allocationDetails[j].Item.ItemNumber);
}
OracleParameter c115_storeno = new OracleParameter();
c115_storeno.OracleDbType = OracleDbType.Int64;
c115_storeno.Value = stores;
OracleParameter c115_itemno = new OracleParameter();
c115_itemno.OracleDbType = OracleDbType.Varchar2;
c115_itemno.Value = itemnumbers;
OracleParameter c115_id = new OracleParameter();
c115_id.OracleDbType = OracleDbType.Int64;
c115_id.Value = ids;
using (var command = dbCon.CreateCommand())
{
command.CommandText = query;
command.CommandType = CommandType.Text;
command.BindByName = true;
command.ArrayBindCount = detailsListDto.Count;
command.Parameters.Add(c115_storeno);
command.Parameters.Add(c115_itemno);
command.Parameters.Add(c115_id);
await command.ExecuteNonQueryAsync();
}
System.ArgumentException:参数绑定无效(参数“c115_storeno”)
更新答案
c115_storeno.Direction = ParameterDirection.Input;
c115_storeno.ParameterName = ":c115_storeno";
c115_itemno.Direction = ParameterDirection.Input;
c115_itemno.ParameterName = ":c115_itemno";
c115_id.Direction = ParameterDirection.Input;
c115_id.ParameterName = ":c115_id";
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)