繁体   English   中英

如何使用C#和SQL将日期添加到列类型为“日期/类型”的MS Access数据库中?

[英]How do I add a date using C# & SQL to an MS Access database with column type 'Date/Type'?

我尝试使用DateTimePicker格式为dd/MM/yyyyDateTimePicker使用插入SQL语句在MS Access数据库的Date/Time列中插入日期。

这是我所做的:

connection.Open();

OleDbCommand command = new OleDbCommand();
command.Connection = connection; // Connecting the command to the connection.
command.CommandText = "insert into [TestEntry] (TestTableID, StudentID, DateOfTest, [DeadLine]) values(" + int.Parse(txtTestName.Text) + ", " + int.Parse(studentID) + ", #" + this.dateTimeStartD.Text + "# , #" + this.dateTimeEndD.Text + "#)";

command.ExecuteNonQuery();
connection.Close();

我不断收到错误

输入的字符串格式不正确

我的Access表中的“日期/时间”列的格式为“短日期”,例如。 2015年12月11日。

任何帮助将不胜感激。

我不认为它来自数据库级别。 当您尝试以不同格式区分值时,将出现此异常。 请检查您的第一个参数是否为insert语句。

int.Parse(txtTestName.Text)

您正在尝试通过将文本框值转换为整数将整数值插入“ TestTableID”字段。 请检查您的文本框输入的是数字还是字符。 应该只是数字。

暂无
暂无

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

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