'C# - ASP.NET - Inserting Date from a calendar into a DataBase
I am trying to store the date from a calendar which the user has selected into a database. It seems to not being inserting it into the Access Database. The DB field data type is Date/Time and the variables are below. I know my Query works because the other information stores correctly.
DateTime dtUserDate;
dtUserDate = calenderUserDate.SelectedDate;
string myQuery = "INSERT INTO MMK( Name, Email, Address, Town, County, PostCode, Country, Telephone, Date Joined) VALUES ( '" + strName + "' , '" + strEmail + "' , '" + strAddress + "' , '" + strTown + "' , '" + strCounty + "' , '" + strPostCode + "' , '" + strCountry + "' , '" + strTeleNumber + "' , '" + dtUserDate+ "')";
Thanks
Solution 1:[1]
try with
INSERT INTO MMK( Name, Email, Address, Town, County, PostCode, Country, Telephone, [Date Joined]) ....
Note that your table column Date Joined
having space, use [Date Joined]
Use Parameters as below
string myQuery = "INSERT INTO MMK( Name, Email, Address, Town, County, PostCode, Country, Telephone, [Date Joined]) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)";
using (var cmd = new OleDbCommand(myQuery, con))
{
cmd.Parameters.AddWithValue("Name", strName);
....
cmd.Parameters.AddWithValue("DateJoined", dtUserDate);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |