I have a csv file and I need add one more column(as-of-date) and save them to an oracle table using c#. What I did was that I add data to Datatable and used OracleBulkCopy to insert all data to db table.
Now the issue is when I check my oracle table in Toad, the first column shows me 10/08/1320 and obviously oracle cannot store date which is older than 1900. And when I ckick the field from Toad, it tells me that "The specified date is out of range for supported dates of ....".
Below are three other solutions I tried and all had the same issue.
using Oracle.DataAcccess.Client;
//Solution 1
DataTable dt = new DataTable();
dt.Columns.Add("Product_Date",typeof(DateTime));//The first column of my oracle table is Date
dt.Columns.Add(....);
...
//loop my csv file
DataRow dr = dt.NewRow();
dr[0] = new DateTime(2013,10,8);
dr[1] = ...;
...
dt.Rows.Add(dr)
OracleBulkCopy bc = new OracleBulkCopy(myConn);
bc.DestinationTableName = "TableName";
bc.WriteToServer(dt);
//Solution 2
DataTable dt = new DataTable();
dt.Columns.Add("Product_Date",typeof(OracleDate));//The first column of my oracle table is Date
dt.Columns.Add(....);
...
//loop my csv file
DataRow dr = dt.NewRow();
DateTime dtime = DateTime(2013,10,8);
dr[0] = new OracleDate(dtime);
dr[1] = ...;
...
dt.Rows.Add(dr)
OracleBulkCopy bc = new OracleBulkCopy(myConn);
bc.DestinationTableName = "TableName";
bc.WriteToServer(dt);
//Solution 3
DataTable dt = new DataTable();
dt.Columns.Add("Product_Date",typeof(string));//The first column of my oracle table is Date
dt.Columns.Add(....);
...
//loop my csv file
DataRow dr = dt.NewRow();
DateTime dtime = DateTime(2013,10,8);
dr[0] = dtime.ToString("ddMMMyy");
dr[1] = ...;
...
dt.Rows.Add(dr)
OracleBulkCopy bc = new OracleBulkCopy(myConn);
bc.DestinationTableName = "TableName";
bc.WriteToServer(dt);