I will revisit the sample list I created for adding items to lists for this example.Here is what the list looks like when displayed in a Grid View.You can easily update a database from a Data Grid View. Step 4See the properties of the Adapter on Data Set, whether it has a query for updating or not. Step 5A line is automatically generated, when you bind the Data Grid View to the dataset.Step 1Create a Windows Forms Application Project, and place a Data Grid View on the form. As: Points of Interest You can insert a row and click the update button; a row in the database will be inserted.Row Updated, New Sql Row Updated Event Handler( Address Of On Row Updated) ' Set Data Adapter command properties, fill Data Set, and modify Data Set. Update(cust DS, "Customers") ' Remove handlers. Row Updated, _ New Sql Row Updated Event Handler(Address Of On Row Updated) Private Shared Sub On Row Updating(sender As Object, _ args As Sql Row Updating Event Args) If args.
Row Updated = new Sql Row Updated Event Handler(On Row Updated); // Set Data Adapter command properties, fill Data Set, modify Data Set. Fill Error, New Fill Error Event Handler( _ Address Of Fill Error) Dim data Set As Data Set = New Data Set adapter. ' Add a row to table using the values from the first two columns. Of course Grid Views have more kinds of events than these listed below, which you can expand this example for your needs (see this link for some more examples). *Please note that in order to keep this example simple, the above code doesn’t account for the situation where an ID doesn’t exist if the user chooses to modify it.See Part 2 for steps on how to customize the controls when switching to Edit mode, including disabling the ID field.Most of this code was gleaned & modified from Microsoft’s documentation on the Grid View Row Editing event.Also see their documentation on all Grid View events.
All your insertions, updates, and deletions will be effected by the single button.