0
 private void button4_Click(object sender, EventArgs e)
        {
            MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;Initial Catalog='liblib';Data Source=localhost;username=root;password=admin");

            String query = "UPDATE loans SET dataRet=@data1 WHERE loans.idloans = @idloan";
            MySqlCommand cmd = new MySqlCommand(query, connection);

            int id = Int32.Parse(textBox9.Text);


                cmd.Parameters.Add("@data1", MySqlDbType.Date).Value = dateTimePicker1.Value;
                cmd.Parameters.Add("@idloan", MySqlDbType.Int32).Value = id;



                connection.Open();

                if (cmd.ExecuteNonQuery() == 1)
                {

                    MessageBox.Show("Succesful!");


                    connection.Close();

                    FIllCard();


                }


            else
            {

                MessageBox.Show("Error");
                connection.Close();
            }

When I execute this UPDATE query in phpmyadmin it works and updates the entry:

UPDATE loans SET dataRet='2017-5-6' WHERE loans.idloans = 23.

But the problem is when I try it in my Form whith parameters. It always returns me "Error" message(ExecuteNonQuery is different from 1), and when I check the database there is no update. The type of the variables in my database are: idloans - int; dataRet = date;

Freak0345
  • 47
  • 8

1 Answers1

0

Check out this post: update a mySQL table using C#, It does not have an answer marked as solution, but the OP of that question has authentication problems after using the code of the first answer, perhaps it works for you

H.J. Meijer
  • 379
  • 2
  • 13