I have an application that displays the data of a sql database in a dataGridView via a dataSet. I was wondering if there was a way of updating the database by modifying the gridViewDirectly, like passing the data from the database to the grid, but inverted, instead of creating a new form that displays the editable info in textboxes and then the user changes what he has to change and clicks update. Is this possible?
2 Answers
the DataGridView
had a already feature to DataSet
with BindingSource
, TableAdapter
and BindingNavigator
Control by manipulating the data from database to DataGridView
just drag and drop to your Form no more codes.
- Create a DataSet
- Drag Table to DataSet
- Go to "Data Sources" panel
- Drag the Table to your Form.
And thats it! as you can see the "Save" and "Delete" button fromBindingNavigator
this will be your function to save, update and delete the data from your database using theDataGridView
withDataSet
i apologize for my short tutorial and not very clear :)
you can put a button column in datagridview and when you press the button you can begin to edit dgv cells.
info: how can i add two buttons to a single datagrid column dynamically?
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewbuttoncolumn.aspx
Define DataGridView Column type Programmatically
If you need any other information about that please feel free to say
Edit:
You can do like this :
DataGridViewButtonColumn clbt_delet = new DataGridViewButtonColumn();
clbt_delete.HeaderText = "DELETE"
clbt_delete.Text = "Delete";
clbt_delete.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(clbt_delete);