The following code snippet for for bulk insert of data from SQL DB into Oracle database.
I have used stored procedure in oracle database with 2 parameters (int and string)
I am getting the below error while executing the query. Please help me to resolve this. or suggest any good solution for bulk data insert.
My Query:
List<int> arrPersonId = new List<int>();
foreach (DataRow row in ds.Tables[0].Rows)
{
arrPersonId.Add(Convert.ToInt32(row["USER_ID"]));
}
List<string> arrPersonName = new List<string>();
foreach (DataRow row in ds.Tables[0].Rows)
{
arrPersonName.Add(row["USERNAME"].ToString());
}
OracleConnection connection = new OracleConnection();
connection.ConnectionString = DAKObj.GetOraConnectionString();
OracleCommand command = new OracleCommand();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "sp_InsertByODPNET";
command.Parameters.Add("@PersonId", OracleDbType.Int32);
command.Parameters[0].Value = arrPersonId;
command.Parameters.Add("@PersonName", OracleDbType.Varchar2, 100);
command.Parameters[1].Value = arrPersonName;
command.ArrayBindCount = arrPersonId.Count;
connection.Open();
command.ExecuteNonQuery();
connection.Close();
Error:-
An exception of type 'System.InvalidCastException' occurred in Oracle.DataAccess.dll but was not handled in user code
Additional information: Unable to cast object of type 'System.Collections.Generic.List`1[System.Int32]' to type 'System.Array'