将参数传递给INSERT的正确语法是什么...在c#中的ON DUPLICATE KEY UPDATE? 我试过这个
MySqlCommand cmd = new MySqlCommand("INSERT INTO table(ID,number,color) VALUES (@r,@c,@e)
ON DUPLICATE KEY UPDATE table (number) VALUES (@c,@e) ", conn);
cmd.Parameters.AddWithValue("@r", id);
cmd.Parameters.AddWithValue("@c", a_name)
cmd.Parameters.AddWithValue("@e", a_color)
cmd.ExecuteNonQuery();
但是这种语法不正确。有什么想法吗?
答案 0 :(得分:1)
INSERT INTO table(ID,number) VALUES (@r,@c) ON DUPLICATE KEY UPDATE number = @c
因此你应该有类似的东西:
MySqlCommand cmd = new MySqlCommand("INSERT INTO table(ID,number) VALUES (@r,@c) ON DUPLICATE KEY UPDATE number = @c ", conn);