Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Better practice by deleting ???
 

Better practice by deleting ???

I have Dragged&Dropped a datasource to a WinForm and got myself a good user interface with the datagridview and the navigator, but ...

When the user DELETEs a row of data in the datagridview and confirms this deleting, the row disappears from the datagridview and I update the database.

BUT maybe the row should NOT be deleted because violation of "Foreign key constraint" - I inform the user of this error but how can I get the "deleted" row back in the datagridview again - it's not a good practice to just FILL in data again because the user COULD have changed some other data in the datagridview and these changes will the be lost !

What are "the best practice" for this deleting ?

Best regards KSO, Denmark
PSAKSor  Monday, April 27, 2009 7:02 AM
Ok
U vcan make sure when deleting, just as the user confirms that he wnts to delete the row ,take that rows data,
and chk in database whether it is being used in some other table(as foreign key) if so then dont perform delete operation , put a msg to user saying cannot be deleted as this particular row data is being used in table(ur table name) . Then the row cannot be removed .

If it is not being used else where then just delete it.

I hope u got what i m trying to say.If u dont,DO let me knw.

Meghana Lohit
meghanalohit  Monday, April 27, 2009 9:40 AM
HI PSAKSorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Based on what i read , i think u want to inform the user that this particular row cannot be deleted due to so n so reasons, and not delete the row???
Correct me if i m wrong

Meghana Lohit
meghanalohit  Monday, April 27, 2009 8:43 AM
Yeah - that's right BUT ...

please remark that I'm using this Drag&Drop-method and then I have not so much code to fool around in !

"By design" I update after every attemp to delete.

These "so n so reasons" in this particular case is "a violation of a foreign key constraint" and this is found out AFTER the row is deleted in the datagridview on the form !

I would like to "find out this FKC-error BEFORE the row is removed from the datagridview.

Best regards KSO, Denmark
PSAKSor  Monday, April 27, 2009 8:54 AM
Ok
U vcan make sure when deleting, just as the user confirms that he wnts to delete the row ,take that rows data,
and chk in database whether it is being used in some other table(as foreign key) if so then dont perform delete operation , put a msg to user saying cannot be deleted as this particular row data is being used in table(ur table name) . Then the row cannot be removed .

If it is not being used else where then just delete it.

I hope u got what i m trying to say.If u dont,DO let me knw.

Meghana Lohit
meghanalohit  Monday, April 27, 2009 9:40 AM
Yeah, yeah you'r so right BUT ...

you don't see: "... that I'm using this Drag&Drop-method and then I have not so much code to fool around in !"

The user maybemake some editation and then deletes a row (I update the db after every deleting !)

- they only thing I can do after the users deletes a rowis start theupdate and THEN "the train is running" and the FKC-error comes up.

I think there MUST be an event like "TryDeleteAndSeeWhatErrorComesUp_IfAny" and the I can manage from here.




Best regards KSO, Denmark
PSAKSor  Monday, April 27, 2009 9:55 AM
Ya no problem if u r using that. I think u must be using a delete button when user deletes a row so u can put this
take that rows data,
and chk in database whether it is being used in some other table(as foreign key) if so then dont perform delete operation , put a msg to user saying cannot be deleted as this particular row data is being used in table(ur table name) . Then the row cannot be removed .

u need not put this in drag and drop method,correct me if i m wrong
Can u tel if u using windows form or User control

Meghana Lohit
meghanalohit  Monday, April 27, 2009 10:00 AM
I use Windows forms.

This Drag&Drop-method for getting a well functioning user interface is fantastic I think BUT ...

I can't imaging that it's created WITHOUT thinking of this kind of error in mind - so I'm sure there must be an "beforedeleteEvent" I can use ... but I can't find our how.

OK you can code, code and code your own solution from scratch, but I try to minimize the amount of code ... but sometimes run into troubles - this is one of them !


Best regards KSO, Denmark
PSAKSor  Monday, April 27, 2009 10:08 AM
meghanalohit  Monday, April 27, 2009 10:12 AM

You can use google to search for other answers

Custom Search

More Threads

• Writing to and Reading from Access Database Problem?
• Bindingsource
• datagrid
• Datagrid - Background color of the cell
• cann't xsd.exe generate partial dataset class with table adapters??
• RowFilter problems
• DataGridView order problem
• center the text in each cell of dataGridView
• When to dispose TableAdapter?
• Bind Data to the Combo in a DataGrid Dynamically