-4
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();
Mike Lischke
  • 42,670
  • 15
  • 104
  • 155

2 Answers2

0

So very obvious. You're missing the ending paranthesis of VALUES. This should work:

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...");
}

Also note that INSERT, UPDATE and DELETE commands should be executed using ExecuteNonQuery().

dotNET
  • 31,005
  • 20
  • 138
  • 226
0

Missing the closing parenthesys for the VALUES clause, but your query should be rewritten to avoid Sql Injection and an INSERT query is executed with ExecuteNonQuery

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...");
Community
  • 1
  • 1
Steve
  • 208,592
  • 21
  • 221
  • 278