By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

SqlDataSource Error Handling

P: 14
I'm working on an admin page for a SQL Server 05 db. The page is in ASP.NET 2.0/C#. The db has multiple tables with foreign keys/constraints.

I have multiple SqlDataSources and GridViews, which are doing the select/update/delete methods. I manually did the Insert method for each Gridview and I am able perform error handling on it.

Expand|Select|Wrap|Line Numbers
  1. Textboxes for data to add
  2. <asp:Button ID="btnInsertNewService runat="server" Text="Submit" OnClick="btnInsertNewService_Click" />
  4. protected void btnInsertNewService_Click(object sender, EventArgs e) 
  5. {
  6. try
  7. {
  8. sdsServices.Insert();
  9. }
  10. catch...Error Handling here...
But if I try to delete from one table with a constraint I get the ugly error screen. I want to be able to do error handling for the Delete method of the SqlDataSource.

So what I tried was just like the Insert. I set the OnClick property of the Delete button in the GridView to a new method that calls sdsServices.Delete(). I get this error though:
"You have specified that your delete command compares all values on SqlDataSource 'sdsServices', but the dictionary passed in for values is empty. Pass in a valid dictionary for delete or change your mode to OverwriteChanges. "

Anything I try to delete on the GridView gets the error. After trying a few different things with that, I looked around found some info that said to use the OnDeleted or OnDeleting for the Gridview and use SqlDataSourceEventArgs for either of those, which allows for error handling.

When I tried it with OnDeleting I would just get an error saying there was no overload for those EventArgs. When I tried it with OnDeleted I would get no errors, but nothing would delete from the GridView.

I hope I have explained this clearly enough. Can anyone point me in the right direction?
May 23 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.