What would be the sql to enter thousands of records into Oracle db with C#?
views:
181answers:
1
+5
A:
Use ODP.NET and array binding:
class Record {
public int Value1 { get; set; }
public int Value2 { get; set; }
}
Record[] records = GetRecords();
const string CMD_TEXT = "INSERT INTO TABLE (Col1, Col2) VALUES (:Col1, :Col2);"
using (var conn = new OracleConnection(connectionString))
using (var cmd = new OracleCommand(CMD_TEXT, conn)) {
cmd.BindByName = true;
// number of rows to insert
cmd.ArrayBindCount = records.Length;
// bind array of values to parameters
cmd.Parameters.Add(":col1", OracleDbType.Int32,
records.Select(r => r.Value1).ToArray()
);
cmd.Parameters.Add(":col2", OracleDbType.Int32,
records.Select(r => r.Value2).ToArray()
);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
Mark Brackett
2008-12-19 21:25:02