user2592096
user2592096

Reputation: 1

UPDATE c# MySQL syn

I want to update a table with the time difference between two events. I've implemented this code:

TimeSpan ts = vett[0] - vett[1]; 
MySqlCommand cmdup = new MySqlCommand();

cmdup.CommandText = "UPDATE event_move SET diff_time=" + ts + "WHERE id_event_move=" + id_move[0];
cmdup.Connection = myConn;
myConn.Open();

cmdup.ExecuteNonQuery();

myConn.Close();

My Visual Studio 2010 indicates a syntax error at the line cmdup.CommandText = ...

Might you help me? Thanks in advance

Upvotes: 0

Views: 64

Answers (2)

Dan Homola
Dan Homola

Reputation: 4575

The source of the mistake is probably the missing space as Giovanni says. My tip would be to use String.Format method.

cmdup.CommandText = String.Format("UPDATE event_move SET diff_time={0} WHERE id_event_move={1}", ts, id_move[0]);

Have you used this, you would spot the missing space immediately.

Upvotes: 2

Giovanni Guarino
Giovanni Guarino

Reputation: 356

Add space before WHERE condiction:

cmdup.CommandText = "UPDATE event_move SET diff_time=" + ts + " WHERE id_event_move=" + id_move[0];

Upvotes: 1

Related Questions