I want to store a date in my database. I have added two keys values in web.config. I have used keyFinancialYr and keyFinancialQtr in my code behind to store those values in my database in two column as financial year and financial quarter. I can store keyFinancialQtr value in my database. But when i try to store keyFinancialYr value it gives error. like this "An exception of type 'System.Data.EvaluateException' occurred in System.Data.dll but was not handled in user code
Additional information: Cannot convert value '-2018' to Type: System.DateTime."
web.config-
<appSettings>
<add key="keyFinancialYr" value="2018-01-01" />
<add key="keyFinancialQtr" value="1" />
</appSettings>
code behind-
DateTime x = Convert.ToDateTime(WebConfigurationManager.AppSettings["keyFinancialYr"]);
int y = Convert.ToInt32(WebConfigurationManager.AppSettings["keyFinancialQtr"]);
using (OleDbConnection excel_con = new OleDbConnection(conString))
{
excel_con.Open();
string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
DataTable dtExcelData = new DataTable();
//[OPTIONAL]: It is recommended as otherwise the data will be considered as String by default.
dtExcelData.Columns.AddRange(new DataColumn[9] { new DataColumn("Id", typeof(int)),
new DataColumn("Banks", typeof(string)),
new DataColumn("Crop Loan", typeof(int)),
new DataColumn("Water Resources", typeof(decimal)),
new DataColumn("Farm Mechanisation", typeof(int)),
new DataColumn("Plantation & Horticulture", typeof(decimal)),
new DataColumn("Forestry & Wasteland Dev.", typeof(int)),
new DataColumn("Financial_Quarter", typeof(int),y.ToString()),
new DataColumn("Financial_yr",typeof(DateTime),x.ToShortDateString())
});