Design Question - DataSet or List - Update Changes - c#

Not sure if I have the correct subject line. Here is my issue. I have a form with 2 GridView. One GridView has a list of all zipCodes. The users is to select a location from a dropdown list, then select the zipcodes he/she wants to be assigned to that location and then click the "Add" button. The zipcodes then appear in the second GridView. When the user clicks the "Save" button, the data is sent to the database. The is also a "Remove" to remove zipcode(s) in the second GridView.
How do I track changes only in the second GridView. There could be 1000's of zipcode in the second GridView. Do I just remove and re-insert the list for that location evertime the user click save? I was thinking of using a DataSet, add DataRows and then update, however I am not using a DataAdapter to load my dataset, so there is no way for me to use DataAdapter.Update(ds). I am using the SQLHelper.ExecuteDataset(parms)
Any ideas?
Anyone?

Forget Dataset. Dataset is a nightmare. Instead use a BindingList.

Related

Why does my GridView control in c# aspnet display an old table below the new table?

The objective i'm trying to achieve is to display filtered data in the same gridcontrol.
So what I do is e.g A-DROPDOWN clicked, display XDATA in GRIDVIEW1. Then FilterA selected, this filter calls the "ADROPDOWN" clicked event again and then checks the appropriate filter then passes the appropriate sql query, then displays "YDATA" in GRIDVIEW1.
Now when I select B-DROPDOWN, ZDATA is displayed however below it is the YDATA. If I select C-DROPDOWN, VDATA is displayed howver below it is still the YDATA.
If I selected A-DROPDOWN then XDATA would be displayed then if I would selected B-DROPDOWN without selecting any of the filters, WDATA would be displayed cleanly in GRIDVIEW1 without any data below or above it. Would appreciate if anyone has any suggestions. Cannot show my code because its 20000 lines.
Would like to add. The alphabets assigned to the dropdowns and data represents the different datasets.
SOLVED !!!
Incase it is of help to someone. my update panel in my front end was only updating the gridview, not the table where the grid view was located . I simple made it so that my entire table where the gridview was located was updating. Many thanks.

How to use BindingSource, datagridView and navigating buttons together

is there any chance to make the navigating buttons operate on the whole database while the datagrid would show only the filtered results? I mean, I have a datagridview and some textboxes corresponding to the columns. When I filter my data, the datagridview gets filled and the textboxes showing the data of the first row. When i move through the datagridview to the next row, the values in the textboxes change correspondingly. Now, I would like to filter first, then to click on a datagrid row. Afterwards,( because i don't need the filtered results any more) i would like just to drop them and to navigate just through common buttons on the whole unfiltered data. For example:
Filter for all Names starting with "S",
DoubleClick on the Row,
Navigate from this entry with the buttons, not
only on the names starting with "S", but to the next or previous
entry in the database.
I know how to navigate using BindingSource.MovePrevious() or MoveNext(), but as long as I use the same bindingSource i navigate through the same filtered set of data.
Any suggestions would be very much appreciated!

asp c# looping through dynamic datatable

asp c#
i have a page where user selects an item and its quantity to purchase and next item and so on
all items selected are filled in datatable and shown in gridview
at the end of selecting items
when user clicks process button
i want to insert all items and its quantities in database
on pageload a datatable is empty
on btn_Select_Click i hv filled in few rows
on btn_Process_Click i want to loop through these rows and insert records in db for each row
but it returns zero rows
Your question is a little vague. "but it returns zero rows"... I'm guessing that what you mean is, that in the click handler for your button, when you access your grid object, it has no rows in it?
Remember that each load of the page creates a whole set of brand new webcontrols. Webcontrol objects are not persisted in memory to be reused on each hit to the page.
If you want the same rows available on this new page that is being rendered after the button click, you have to re-bind your grid. I'm guessing that isn't happening in your code.

DataGrid problems. Using DataSet.Merge with "Edit Template"

I am trying to debug an issue with a WinForm application.
The application uses a DataGridView bound to a DataSet.
The user can select a row and click "Edit" and an Edit Form appears so the user can edit the row and save his changes.
If the DataGridView is sorted by one or more columns and the user edits a row more than once and changes that rows position in the DataGrid (by changing one of the sorted columns TWICE), the DataGridView gets out of sync and I get Exception errors.
Here is how the code is written:
When the user clicks a row and hits edit (the user may only select one row), that row is passed to the EditFom. The edit Form creates an empty DataSet and loads that Row. When the user is done, the calling form uses DataSet.Merge to merge those changes back into its DataSet.
Here are a couple of scenarios that tell me it is womething to do with the "merge" and sorting:
(Note, I never change the actual "sorting", I am talking about changing the value of one of the sorted by columns in one of the rows.)
If the user edits a row directly in the Grid and changes the value of one of the columns being used to sort, then changes it again, etc. The row moves around the Grid, like it should and when the user clicks save, everything saves fine.
If the user edits a row (directly in the Grid OR via the "template") and doesnt change any of the "sort" columns, just makes an edit (therby setting the "State" of the row to Modified, right...), THEN the user edits the row using the Template (which goes through the seperate DataSet and merges the data back when done), and changes one of the columns being sorted (when done, the grid should resort and the row should "move"), the row doesn't get REPAINTED, it stays in the same position in the grid that it was in before the template edit. (Although, the data saves fine and you can refresh the grid and it sorts properly.) Evidently, the DataGrid isn't being notified that the RowChanged in this scenario (or it is, but it isn't doing anything about it).
If the user edits a row directly in the Grid, change a sort column (the row moves), then edits the row using the template and changes that column again, we get the same results as 2, above. The data saves fine, but when the user leaves the edit template, the grid doesn't resort.
(This is the one that causes the Exception error.)
If the user edits a row using the template and changes a sort column and leaves the template, the datagrid resorts and the row moves properly. Then, if the user edits the SAME row using the Template Edit and changes the sort column AGAIN. When the user leaves the edit template, the datagrid doesn't resort and when the user saves the data and the grid refreshes, we get an error:
System.InvalidOperationException: DataTable internal index is corrupted: '5'.
And sometimes, we get an error complaining the primary key is missing.
Any advice on how to "debug" this? I feel like it has something to do with the "internediate" dataset the edit template uses and the "Merge". It is like the DataGrid datasource is getting out of sync with the DataGrid Rows.
I should have done some Google'ing before posting this. It seems to be a common error and I found a HUGE post about this on the MS site. Unfortunately, I haev tried most of their suggestions, but most likely I will find my answer there. I just wanted to make a note of this, in case anyone is interested:
http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/18544cd3-1083-45fe-b9e7-bb34482b68dd

Undo records modified using gridview if user clicks Cancel

I've got a user modification page, that displays a list of reports a user has access to using a GridView object.
What I want to do is, if someone makes a bunch of changes to a users page, but then clicks cancel, all changes that are made will be undone.
My main issue here is the GridView, which has add/delete/modify buttons, tied to a separate table.
So if I open my own page, add a new report to the gridview, then hit cancel, I don't want that report to be saved to my account..
Likewise, if I delete a record, and then hit cancel, the record is not deleted.
What is the best way to do this?
You need to maintain this in the datatable and put this in a Session variable and bind your gridview to your datatable that is in the session. So once you are finished with the changes and want to submit the changes in the DB, you have to play with Datatable Row State, from which you can find which row is added and which one is Deleted or Modified.
Have a look at this article to understand Datatable Row state
system.data.datarow.rowstate
In such case you mustn't bind GridView to the real datasource (Entity framework). If you do it changes will be written to the database and you will have very hard time to roll them back. GridView must work with temporary data stored for example in the session and only after commiting changes (Save button on the page) the data will be written to the database by EF.

Categories