我还在使用我的第一个数据库/时间跟踪解决方案。
现在我可以创建一个新用户和一个包含用户名和列
的表[ID] AUTOINCREMENT NOT NULL PRIMARY KEY,
[Datum] Text,
[Beginn] Text,
[Ende] Text,
[Pause] Text,
[Arbeitszeit] Text
对于下一步,我使用以下方法将新数据插入表中:
command.CommandText = "insert into " + user + " (Date, Begin, End, Pause, Worktime) values ('" + dateTimePicker1.Text + "', '" + Begin + "', '" + End + "', '" + Pause + "', '"+ Worktime+"')";
开始,结束,暂停和工作时间事先声明为字符串。到目前为止,这完全正常。
但是现在我正在尝试更新/更改插入数据的值,但它并没有真正起作用。
我现在正在使用以下代码:
OleDbCommand command = new OleDbCommand();
OleDbCommand cmd = new OleDbCommand();
cmd.Parameters.AddWithValue("@Date", Date);
cmd.Parameters.AddWithValue("@Begin", Begin);
cmd.Parameters.AddWithValue("@End", End);
cmd.Parameters.AddWithValue("@Pause", Pause);
cmd.Parameters.AddWithValue("@Worktime", Worktime);
cmd.Parameters.AddWithValue("@ID", ID);
command.Connection = con;
command.CommandText = "update" + user + " set [Date] =@Date [Text], [Begin] =@Begin [Text], [End] =@End [Text], [Pause] =@Pause [Text], [Worktime] =@Worktime [Text] where ID = @ID;";
con.Open();
command.ExecuteNonQuery();
con.Close();
我得到的错误是:
System.Data.OleDb.OleDbException(0x80040E14)非法SQL-Instruction; '删除',' INSERT',' SELECT','程序'或者'更新'预期
错误发生在
行上command.ExecuteNonQuery();
如果有人能帮助我,我真的很高兴。
答案 0 :(得分:1)
更新后缺少空格,请更改为:
command.CommandText = "update " + user + " set [Date] =@Date [Text], [Begin] =@Begin [Text], [End] =@End [Text], [Pause] =@Pause [Text], [Worktime] =@Worktime [Text] where ID = @ID;";
答案 1 :(得分:0)
而不是
command.CommandText = "update" + user + " set [Date] =@Date [Text], [Begin] =@Begin [Text], [End] =@End [Text], [Pause] =@Pause [Text], [Worktime] =@Worktime [Text] where ID = @ID;";
试试这个
command.CommandText = "update " + user + " set [Date] =@Date [Text], [Begin] =@Begin [Text], [End] =@End [Text], [Pause] =@Pause [Text], [Worktime] =@Worktime [Text] where ID = @ID";