string query2 = "INSERT INTO library_database.status_of_issue VALUES('";
query2 = query2 +textBox2.Text + "','";
query2 = query2 + textBox1.Text + "', CURDATE(),ADDDATE(CURDATE(), INTERVAL 14 DAY)";
cmd = new MySqlCommand(query2, con);
MySqlDataReader d1 = cmd.ExecuteReader();
MessageBox.Show("Issed...");
d1.Close();
答案 0 :(得分:0)
非常明显。你错过了VALUES的结束语。这应该有效:
string query2 = string.Format("INSERT INTO library_database.status_of_issue VALUES('{0}', '{1}', CURDATE(), ADDDATE(CURDATE(), INTERVAL 14 DAY))", textBox2.Text, textBox1.Text);
using(var cmd = new MySqlCommand(query2, con))
{
if(cmd.ExecuteNonQuery() > 0)
MessageBox.Show("Issed...");
}
另请注意,应使用ExecuteNonQuery()
执行INSERT,UPDATE和DELETE命令。
答案 1 :(得分:0)
缺少VALUES子句的右括号,但应重写您的查询以避免Sql Injection并使用ExecuteNonQuery
执行INSERT查询
string query2 = @"INSERT INTO library_database.status_of_issue VALUES(@p1, @p2,
CURDATE(),ADDDATE(CURDATE(), INTERVAL 14 DAY))";
cmd = new MySqlCommand(query2, con);
cmd.Parameters.AddWithValue("@p1", textBox2.Text);
cmd.Parameters.AddWithValue("@p2", textBox1.Text);
int rows = cmd.ExecuteNonQuery();
if(rows > 0)
MessageBox.Show("insert OK...");