Hello
I have a problem inserting a datetime format variable to Sql Server 2005 database. DateTime Format is dd.MM.yyyy
conn.Open();
string conString = "SET DATEFORMAT DMY INSERT INTO AmortPlanT (InvestmentID,StartDate,Maturity,IRate,CoupPerYear,parValue) Values (@IIndex,'@StartDate','@Maturity',@IRate,@CouponPerYear,@parValue)";
using (SqlCommand myCommand = new SqlCommand(conString, conn))
{
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.Add("@IIndex", SqlDbType.Int).Value = investmentIndex;
myCommand.Parameters.Add("@StartDate", SqlDbType.DateTime).Value = startDate;
myCommand.Parameters.Add("@Maturity", SqlDbType.DateTime).Value = maturity;
myCommand.Parameters.Add("@IRate", SqlDbType.Float).Value = iRate;
myCommand.Parameters.Add("@CouponPerYear", SqlDbType.Int).Value = coupPerYear;
myCommand.Parameters.Add("@parValue", SqlDbType.Float).Value = parValue;
myCommand.ExecuteNonQuery();
}
StartDate and Maturity are DateTime variables i get from dateTimePicker.Value .
And i'm always getting the error:
Conversion failed when converting datetime from character string.
Thank you for your help.