Updating SQL database from DataGridView C# - c#

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?

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 from BindingNavigator this will be your function to save, update and delete the data from your database using the DataGridView with DataSet
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);

Related

Create a sqlite table from datagridview in C#

I have a datagridview in my C# form App.
How can I create a table directly from datagridview whenever a button is pressed.
Since the datagridview is editable I don't know how many rows of columns there will be to save in the database.
How can I save the whole datagridview to a database and retrieve them?
Can I use a unique id as a table name and then use that??

How to insert, update, delete inside datagridview?

Hi guys I searched for lot on this topic but don't get any result. I want to know it is possible to add, update, delete inside datagridview in c# means i want to add new row and data inside the editable datagridview not from the forms control. I want to place Add New, edit, delete button or anything inside datagridview. In google there is lot of tutorials for this but from the form controls. This is possible in gridview control but i want to know this is also possible in datagridview or not If you have any link related to this then plz inform me. Thanks in advance!
You can Add new DataSet to your project, drag into it by DataSet Designer the table that you want edit with DataGridView by drag and drop from the Server Explorer to DataSet Designer, the runtime will create all the action to interact with you Dataset and TableAdapter, back into Form designer open Data Source Panel Drag your table under dataset to your Form .... done!
Next step it will call Update Method by single button here is the code:
this.nameOfYourTableAdapter.Update(this.nameOfYourDataSet.nameOfYourTable);
ref: Microsoft MSDN

Using Radgridview directly for data Manipulation

So i am using RadGridView for Winforms.
Now what i want to do is to perform data manipulation in the radgridview and datasource to get updated after the row loses foucs. I don't want to use textboxes or any other control for entering data.
Something like this
And after i press the new add new row and enter data
Now this data isn't being updated in the dataSource to update i need a query that needs to executed against the datasource.
Now i haven't been able to build a query because i haven't been able to figure out how to access the data of the newly created cells so that i can build a query and pass to SQLCeDataAdapter for execution.
Any pointers will be appreciated.
Im not sure about RadGridView, but I use DataGridView, wich I guess works the same way
You need to get the datarow so u can update to the database
DataRow row = ((DataRowView)eTipoDocumentoBindingSource.Current).Row;
once you have it, you can use the DataTableAdapter method update(row) to save changes to the database
You can do that, either in the click event of a save button, or in the event of focused row changed

Save values from DataGridview, show them everytime after opening

I have a question about saving values of Datatable or DataGridView. I made a windows form and binded datatable to datagridview. Now i want the values from this datagridview be there everytime i open the windows form. Because sometimes the user add some rows to DGV and when i open it again, the rows are not there any more. Can anyone help me with it?
I think you can do that in this way.
When user adds a row to DataGridView, you can add that row to DGV just for showing it to user. But when the program is closing you can add that rows to the source of DGV, from where you read all data.

C# Adding new rows in DataGridView and database (Access)

I am working on a billing form and i plan to do it in DataGridView to display the Item Name, Quantity, Price, etc. In addition to that, I also intend to add button controls such as snacks and drinks, which would automatically add rows into the DataGridView when selected. My DataGridView is binded to a DataSource. My question is, how do i go about achieving (a) Automatically adding rows into DataGridView after selecting a Beverage from any Beverage button and (b) Inserting these records into the database as well. Any sort of guidance will be greatly appreciated, cheers! :)
Create a Datatable dynamically make it as datasource
Check this link for creating datatable dynamically
after creating it add
datagrid.DataSource=dt;

Categories