繁体   English   中英

C#-ASP.NET-将日历中的日期插入数据库

[英]C# - ASP.NET - Inserting Date from a calendar into a DataBase

我试图将用户选择的日历中的日期存储到数据库中。 似乎没有将其插入到Access数据库中。 DB字段数据类型为日期/时间,变量在下面。 我知道我的查询有效,因为其他信息可以正确存储。

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+ "')";

谢谢

尝试

INSERT INTO MMK( Name, Email, Address, Town, County, PostCode, Country, Telephone, [Date Joined]) ....

请注意,您的表列“ Date Joined有空格,请使用[Date Joined]

使用参数如下

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM