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;

3
  • Does this error occur for any query, or only for this one? Commented May 2, 2018 at 8:18
  • Only update. Insert queries are working. Commented May 2, 2018 at 8:19
  • 1
    Perhaps you should check what the error produced is if its not returning 1 it suggests its finding more than 1 Or none.. Commented May 2, 2018 at 8:23

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.