vendredi 3 avril 2015

Storing data from DataGridView to database

I need to load data from one table into datagridview and after making changes to data store the content into another table.


This is how I get records from table and bind to datagridview



private MySqlCommand myCmdQuery = new MySqlCommand();
private MySqlCommand myStoredProcQuery;
private MySqlDataAdapter myDA = new MySqlDataAdapter();
private BindingSource bS = new BindingSource();
private MySqlCommandBuilder myCB = new MySqlCommandBuilder();
private DataSet ds = new DataSet();

public BindingSource BindToGrid(string sQuery)
{
mySqlDataAdapter = new MySqlDataAdapter();
mySqlDataAdapter.SelectCommand = new MySqlCommand(sQuery, this.connection);
MySqlCommandBuilder myCommandBuilder = new MySqlCommandBuilder(mySqlDataAdapter);

DataSet myDataSet = new DataSet();
dataTable = new DataTable();
mySqlDataAdapter.Fill(myDataSet, "Tablica");
mySqlDataAdapter.Fill(dataTable);

bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;

return bindingSource;
}

gridControl.DataSource = BindToGrid(query);


When I make some changes on data from datagridview how can I save content of datagrid to table without traversing through grid and making insert or update statement for each row?


Aucun commentaire:

Enregistrer un commentaire