473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

SqlDataSource Error Handling

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" />
  3.  
  4. protected void btnInsertNewService_Click(object sender, EventArgs e) 
  5. {
  6. try
  7. {
  8. sdsServices.Insert();
  9. }
  10. catch...Error Handling here...
  11.  
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
0 3602

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

Similar topics

8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
4
by: Jed | last post by:
I have a SqlDataSource bound to DataView control. When the selected index of the DataView changes I would like to get the value of a field (column) from the bound Row. The column's visible...
1
by: JeffDotNet | last post by:
I have been enjoying the declarative use of the new sqlDataSource in asp2.0. It makes paging and query building extremely quick and simple. However occasionally I expect to get a timeout...
4
by: Rob | last post by:
Hey all, So.. a simple FormView/SqlDataSource to handle inserting records into a table. The table has a primary key that the user enters (eg DiscountCode). If the user enters a duplicate the...
1
by: | last post by:
Is there a way to handle when you're on insert mode on a formview and the record you're about to save to the database already exist and insted you rather update instead of inserting and getting an...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
2
by: Brad Isaacs | last post by:
Good evening friends, I have added a Drop Down List box control to my web form. I am using the web.config connection string to access my SQL Server 2000 db. Inside that db I have a table named...
3
by: Mechanic | last post by:
I set up a Server 2003 R2 64-bit server to run ODP.NET.... That all works fine in 32-BIT mode except 1 thing. When I use asp:SqlDataSource tag on this machine I get this error. This application...
0
by: staeri | last post by:
I have a dropdownlist attached to a SqlDataSource inside an Accordion. I receive the following error message when the SqlDataSource is inside the Accordion: "The DataSourceID of 'ddGroup' must...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.