I am inserting DateTime into database, but exception is giving that
Error converting data type nvarchar to DateTime on below line, i have data type in database DateTime of A_Date value
objCmd.Parameters.AddWithValue("@A_Date", A_Date);
string Atten_Date = null;
string TimeIN_ID = null;
string TimeOut_ID = null;
TimeOut_ID = idwEnrollNumber.ToString() + "" + idwYear + "" + Convert.ToString(idwMonth).PadLeft(2, '0') + "" + idwDay.ToString().PadLeft(2, '0');
TimeIN_ID = idwEnrollNumber.ToString() + "" + idwYear + "" + idwMonth.ToString().PadLeft(2, '0') + "" + idwDay.ToString().PadLeft(2, '0') + "" + idwHour.ToString().PadLeft(2, '0') + "" + idwMinute.ToString().PadLeft(2, '0');
A_Date = "'" + idwYear.ToString() + "-" + idwMonth.ToString().PadLeft(2, '0') + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + "'";
Insert_Data(idwEnrollNumber.ToString(), idwVerifyMode.ToString(), idwInOutMode.ToString(), Atten_Date, M_IP, Atten_Date, TimeIN_ID, TimeOut_ID);
private void Insert_Data(string EnrollNumber, string VerifyMode, string idwInOutMode, string A_Date, string M_IP, string A_Time, string TimeIN_ID, string TimeOutId)
{
SqlConnection objConn = null;
try
{
objConn = new SqlConnection("Data Source=server1\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=SilverProduction;MultipleActiveResultSets=True;");
string sSQL = "SP_Insert_Time_Machine";
SqlCommand objCmd = new SqlCommand(sSQL, objConn);
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Parameters.AddWithValue("@EnrollNumber", EnrollNumber);
objCmd.Parameters.AddWithValue("@VerifyMode", VerifyMode);
objCmd.Parameters.AddWithValue("@idwInOutMode", idwInOutMode);
objCmd.Parameters.AddWithValue("@A_Date", A_Date);
objCmd.Parameters.AddWithValue("@Machine_IP", M_IP);
objCmd.Parameters.AddWithValue("@A_Time", A_Time);
objCmd.Parameters.AddWithValue("@TimeInID", TimeIN_ID);
objCmd.Parameters.AddWithValue("@TimeOutId", TimeOutId);
objConn.Open();
objCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
objConn.Close();
}
}