我有一个数据库,其中有一个名为Schedule
. 它看起来像这样:
Schedule
--------
ScheduleID (number)
BackupID (number)
Repository (text)
Interval (text)
Type (text)
现在我正在尝试将值插入此表中,如下所示:
List<string> scheduleData = this.scheduler.getSchedule();
string repository = scheduleData[0];
string interval = scheduleData[1];
string type = scheduleData[2];
List<string> selectedBackup = this.backupForm.getSelectedUser();
string backupID = selectedBackup[0];
string connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\db\\dbBackupUtility.mdb";
OleDbConnection conn = new OleDbConnection(connetionString);
conn.Open();
OleDbCommand sql = new OleDbCommand("INSERT INTO Schedule (BackupID, Repository, Interval, Type) VALUES (@BackupID, @Repository, @Interval, @Type)", conn);
sql.Parameters.AddWithValue("@BackupID", backupID);
sql.Parameters.AddWithValue("@Repository", repository);
sql.Parameters.AddWithValue("@Interval", interval);
sql.Parameters.AddWithValue("@Type", type);
sql.ExecuteNonQuery();
conn.Close();
但是,每次程序执行此行时,我都会收到 OleDbException:
sql.ExecuteNonQuery();
我看不到有关异常的任何其他信息,但我尝试使用 VS 中的查询分析器手动插入值,这很奇怪。我已经用阅读器或适配器尝试了上述方法,但每次都会遇到同样的错误......
异常文本:
Message: "Syntax error in INSERT statement"
StackTrace = "at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at WindowsFormsApplication1.BackupUtility.scheduler_VisibleChanged(Object sender, EventArgs e) in c:\Users\Teichler\Dropbox\VS_Projects\Projects\WindowsFormsApplication1\WindowsFormsApplication1\MainForm.cs:Line104."
Inner Exception: null