I have a gridview and sqldatasource.
I’m trying to insert new records in database and the Date column type is Date and default format is US , mm/dd/yyyy and I’m trying to insert a date with another format.
SqlDataSource2.InsertCommand = "Insert into test (Name,Date) VALUES (@Name,@CONVERT(Date,'@Date',104))";
SqlDataSource2.InsertParameters.Add("Name", nameText);
SqlDataSource2.InsertParameters.Add("Date", DbType.DateTime, date.Text);
I get: String was not recognized as a valid DateTime.
Thanks
The Date type in format agnostic in the database (unless you store it as a string).
You may first try to get a valid
System.DateTimeobject usingDateTime.ParseExactorDateTime.Parse.Then, set the SqlParameter with this value.