473,624 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDataSource Error Handling

14 New Member
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.Del ete(). 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 OverwriteChange s. "

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 SqlDataSourceEv entArgs 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 3617

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

Similar topics

8
5029
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 select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for my GridView/SqlDataSource combinations. I typically select from a view and update the corresponding...
4
3467
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 property is false. I thought I would be able to handle the selected event of the SqlDataSource and get the Row data, but there is nothing there. Where are the SqlDataSourceView items? The DataView's selected item doesn't have a DataItem, so I can't...
1
1677
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 exception. Without filling the sqlDataSource manually I don’t know how to go about catching an exception. (Most likely but not limited to a timeout exception) I certainly don’t want to leave an unhandled the exception. And I would like to give a...
4
13533
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 database complains about a primary key violation (which is what I want) and an exception is thrown. The OnInserted event of the SqlDataSource provides access to the exception so, presumably, you can provide nice handling for various errors. For...
1
1673
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 error of primary key? Thanks, Victor
5
7681
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, the compiler believes an SQL db is being accessed ("An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does...
2
2463
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 Provinces. The table contains 3 fields : LanguageID ProvinceID
3
2705
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 runs fine on all the other machines. Unable to find the requested .Net Framework Data Provider. It may not be installed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
0
1252
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 be the ID of a control of type IDataSource. A control with ID 'SqlDataSourceGroup' could not be found." I've been suggested to move the SqlDataSource out of the Accordion to get rid of the error message above, but when I do so the SqlDataSource
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.