I'm still working at my first database / time tracking solution.
Right now I can create a new user and a table with the Name of the user and the columns
[ID] AUTOINCREMENT NOT NULL PRIMARY KEY,
[Datum] Text,
[Beginn] Text,
[Ende] Text,
[Pause] Text,
[Arbeitszeit] Text
For the next step I inserted new data into the table by using:
command.CommandText = "insert into " + user + " (Date, Begin, End, Pause, Worktime) values ('" + dateTimePicker1.Text + "', '" + Begin + "', '" + End + "', '" + Pause + "', '"+ Worktime+"')";
Begin, End, Pause and Worktime were declared beforehand as strings. That works perfectly fine so far.
But now I'm trying to update/Change the values of the inserted Data and it's not really working.
I'm using the following code right now:
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();
The error I am getting is:
System.Data.OleDb.OleDbException (0x80040E14) illegal SQL-Instruction; 'DELETE', 'INSERT', 'SELECT', 'PROCEDURE' or 'UPDATE' expected.
The error occurs on the line
command.ExecuteNonQuery();
If anyone could help me with this I'd be really glad.
missing blank space after update , change to this :
command.CommandText = "update " + user + " set [Date] =@Date [Text], [Begin] =@Begin [Text], [End] =@End [Text], [Pause] =@Pause [Text], [Worktime] =@Worktime [Text] where ID = @ID;";
Instead of
command.CommandText = "update" + user + " set [Date] =@Date [Text], [Begin] =@Begin [Text], [End] =@End [Text], [Pause] =@Pause [Text], [Worktime] =@Worktime [Text] where ID = @ID;";
try this
command.CommandText = "update " + user + " set [Date] =@Date [Text], [Begin] =@Begin [Text], [End] =@End [Text], [Pause] =@Pause [Text], [Worktime] =@Worktime [Text] where ID = @ID";
User contributions licensed under CC BY-SA 3.0