1

Picture of Visual Studio Project

Hi,

Hope someone can help. I am trying to create a vehicle log for the company I work for. I have managed to get the dataGridView to add a row to the database but, This is what I have found on the internet and it seams to work. Can anyone tell me if this is the correct way of updating the MySQL database from a dataGridView?

NOTE: I added a timer tick so that if anyone added a new line, then the data in the dataGridView it automatically updates the MySQL database.

// saves the data in the dataGridView to the MySQL database
    private void Timer1_Tick(object sender, EventArgs e)
    {
        //int index = vehiclemovementDataGridView.SelectedRows[0].Index;
        //vehiclemovementDataGridView.Rows.
        vehiclemovementTableAdapter.Update(this.vehiclelogDataSet.vehiclemovement);
        //vehiclemovementDataGridView.Update(this.vehiclelogDataSet.vehiclemovement);
    }

In have not typed the connection to the database I added a dataGridView and configured it to connect the MySQL database.

1 Answer 1

1

What you are doing should work according to this link

But you could also try replacing the line:

vehiclemovementTableAdapter.Update(this.vehiclelogDataSet.vehiclemovement);

with

vehiclemovementTableAdapter.Update(vehiclemovementDataTable)

where vehiclemovementDataTable is the data table converted from the data grid view (You would have to add this code yourself). Either should be okay, however the way you are doing it is most likely better and more efficient.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.