You are getting the problem because you are referring to columns[
38] in your poorly formed SQL statement. There are only 38 entries in that array and they start at
0 ... so columns[38] would be the
39th entry - it doesn't exist, hence the error.
You should use parameterised queries - don't concatenate strings to generate sql statements - see
Give me parameterized SQL, or give me death[
^]
That whole function can be much simpler in other ways too - there is no need to transpose the data into another array and having a Try-Catch block with nothing in the Catch block is a heinous crime - you will just "swallow" any errors and lose valuable information.
Try something like this:
private void InsertData()
{
for (int i = 0; i < Data.Rows.Count; i++)
{
conn.Open();
string Ora = "INSERT INTO WBR70(AMC_CODE,FOLIO_NO,INVESTOR_NM,PROD_CODE,PROD_NAME,TRXN_TYPE,TRXN_NO,BROK_DLR_CODE,AE_CODE,TRADE_DATE,PLOT_UNITS,PLOT_AMOUNT,BROKER_PERC,TOTAL_UPFRONT,DEFER_UPFRONT,ADDL_PER,TOT_ADDL_UPFRONT,ADDL_UPFRONT,SPL_PERC,TOT_SPL_UPFRONT,SPL_UPFRONT,PAYABLE_INST,TRXN_CHARG,TER_LOC,DEFER_FREQ,SYS_REG_DATE,AUTO_TRXN_NO,DEFER_NO_OF_INST,SUB_BROKER_ARN,ARN_EMP_CODE,EUIN_VALID,USER_CODE,USER_TRXNNO,TRXN_NATURE,PAN,POSTED_DATE,PAYABLE,BRK_POSTED,BILL_DT)";
Ora += "VALUES(@c0,@c1,@c2,@c3,@c4,@c5,@c6,@c7,@c8,@c9,@c10,@c11,@c12,@c13,@c14,@c15,@c16,@c17,@c18,@c19,@c20,@c21,@c22,@c23,@c24,@c25,@c26,@c27,@c28,@c29,@c30,@c31,@c32,@c33,@c34,@c35,@c36,@c37)";
var cmd = new OracleCommand(Ora, conn);
for (var j = 0; j < Data.Columns.Count; j++)
{
cmd.Parameters.AddWithValue(String.Format("@c{0}", j), Data.Rows[i][j].ToString());
}
cmd.ExecuteNonQuery();
conn.Close();
}
}