![](/img/trans.png)
[英]How do I compare date from database and current date in ms access using C#?
[英]How do I add a date using C# & SQL to an MS Access database with column type 'Date/Type'?
我嘗試使用DateTimePicker
格式為dd/MM/yyyy
的DateTimePicker
使用插入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.