Hi All Experts,

I am a newbie to C#, my development environment is:

Visual Studio 2010 Ultimate Edition
Sql Server 2005
Programming Language C#

I've a form with Unbound Datagridview, from which data is save to Sql Server 2005 by looping through For..Each and pass SQL INSERT Statement when user clicks Save button without any problem. Now what I need is a way that for same Save button, if data is saved in Sql Server then DataGridView will bind to that records so that if user want to Update/Delete/Add data he/she just need to edit the data and again press Save button. All records will share the same unique ID. It's a products database, and when user click save it will generate a transaction Id same for all products user enter when saving. So I think I need to generate a Select statement and retrieve all those records user save through that Unique ID, but then how to bind it to DataGridView datasource and how to Update/Delete through SqlAdapter or other?

Thanks and best regards

Ahmed

I'm assuming that you're hard coding it without adding a datasource so take a look at this MSDN like. It shows how you can retreive data from your database and bind it to your DataGridView (DGV) manually.

To delete a record you could just delete it from the DGV and then reverse what you did to bind the data to the DGV (but insert or update instead of select).

There is a a way of binging the DGV using the data binding wizard but you need to have a data source linked in your project linked to your database.

Let me know how you get on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.