473,834 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Catch errors when updating a DetailsView control

Hi,

I have a DetailsView control bound to a SqlDataSource. I've got
everything working nearly as I want, but here's my problem.

I have a table which has a Guid as a Primary Key, and a VarChar field
(a Title) which is also unique. If the user edits the Title field in
the DetailsView to make it a duplicate, and hits Update, an exception
is thrown (SQLException - statement cancelled as it would violate the
key restrictions).

I was under the impression that regardless of the outcome, the
ItemUpdated event of the DetailsView control would fire, and I could
then check the Exception properties of the event arguments, and act
accordingly.

How can I catch these errors - I have no control over the code where
the error's occurring, so I can't put a try-catch block in? Can I do
this, or do I have to faff around making sure they don't happen before
it tries to save the changes? And if I can't do this, when do the
Exception properties of the ItemUpdated event arguments ever get
used...???

Any help much appreciated!

Cheers.

Stuart

Jan 25 '06 #1
3 3132
You need to post more accurate information rather than have us Guess what
your table design is. It sounds to me like the GUID in the current record is
being used as the PK in the duplicate, this is not allowed.

Post your data description for this table and relevent code.

--
Best Regards

The Inimitable Mr Newbie º¿º
<st************ @gmail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi,

I have a DetailsView control bound to a SqlDataSource. I've got
everything working nearly as I want, but here's my problem.

I have a table which has a Guid as a Primary Key, and a VarChar field
(a Title) which is also unique. If the user edits the Title field in
the DetailsView to make it a duplicate, and hits Update, an exception
is thrown (SQLException - statement cancelled as it would violate the
key restrictions).

I was under the impression that regardless of the outcome, the
ItemUpdated event of the DetailsView control would fire, and I could
then check the Exception properties of the event arguments, and act
accordingly.

How can I catch these errors - I have no control over the code where
the error's occurring, so I can't put a try-catch block in? Can I do
this, or do I have to faff around making sure they don't happen before
it tries to save the changes? And if I can't do this, when do the
Exception properties of the ItemUpdated event arguments ever get
used...???

Any help much appreciated!

Cheers.

Stuart

Jan 25 '06 #2
It isn't anything to do with the Guid. The Title field is also a key.
If I change the title field to a value which is also in the table, then
it throws the error below (I couldn't get the description last night,
as I was at home). How can I catch this error, or get the DetailsView
or SqlDataSource to catch it for me, and keep it so I can check on it?
As far as I'm concerned that's all I need to tell you - I don't want to
confuse the issue by pasting the full schema of a massive table when I
know precisely what's going wrong - I just want to catch it! And as
for what code is being executed - there isn't any, it's all handled by
the DetailsView! Hence my puzzlement.

Violation of UNIQUE KEY constraint 'IX_TableName_1 '. Cannot insert
duplicate key in object 'dbo.TableName.
The statement has been terminated.

This key is the one referring to the Title field.

Stack trace follows, in case you need it:
[SqlException (0x80131904): Violation of UNIQUE KEY constraint
'IX_Courses_1'. Cannot insert duplicate key in object 'dbo.Courses'.
The statement has been terminated.]
System.Data.Sql Client.SqlConne ction.OnError(S qlException exception,
Boolean breakConnection ) +177
System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion
exception, Boolean breakConnection ) +68

System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct
stateObj) +199
System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj)
+2300
System.Data.Sql Client.SqlComma nd.FinishExecut eReader(SqlData Reader
ds, RunBehavior runBehavior, String resetOptionsStr ing) +147
System.Data.Sql Client.SqlComma nd.RunExecuteRe aderTds(Command Behavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async) +1021
System.Data.Sql Client.SqlComma nd.RunExecuteRe ader(CommandBeh avior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result) +314

System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult
result, String methodName, Boolean sendToPipe) +413
System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +115

System.Web.UI.W ebControls.SqlD ataSourceView.E xecuteDbCommand (DbCommand
command, DataSourceOpera tion operation) +392

System.Web.UI.W ebControls.SqlD ataSourceView.E xecuteUpdate(ID ictionary
keys, IDictionary values, IDictionary oldValues) +643
System.Web.UI.D ataSourceView.U pdate(IDictiona ry keys, IDictionary
values, IDictionary oldValues, DataSourceViewO perationCallbac k
callback) +78
System.Web.UI.W ebControls.Deta ilsView.HandleU pdate(String
commandArg, Boolean causesValidatio n) +1153
System.Web.UI.W ebControls.Deta ilsView.HandleE vent(EventArgs e,
Boolean causesValidatio n, String validationGroup ) +450
System.Web.UI.W ebControls.Deta ilsView.OnBubbl eEvent(Object source,
EventArgs e) +88
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs
args) +35
System.Web.UI.W ebControls.Deta ilsViewRow.OnBu bbleEvent(Objec t
source, EventArgs e) +109
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs
args) +35
System.Web.UI.W ebControls.Butt on.OnCommand(Co mmandEventArgs e) +86
System.Web.UI.W ebControls.Butt on.RaisePostBac kEvent(String
eventArgument) +155

System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
eventArgument) +7
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
+33
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
+4921

Jan 26 '06 #3
Fixed it.

Setting e.ExceptionHand led = True rather than False seems to work just
fine. D'oh!

Jan 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1161
by: Roger | last post by:
Got a GridView control on screen - users can select a record from this and it shows up details of selected record in a DetailsView control. DetailsView control is set to allow Updates & Inserts. Inserts work fine but updates dont give any errors but also dont update the record? Any ideas what I'm doing wrong? THanks Roger
1
3372
by: womblesjc | last post by:
I have a data bound Details View control in asp.net 2.0 that formats a phone number. The 'Default Mode' for the control is set to Edit. The phone number field is a template field and I can successfully call a function that formats the phone number when the control is filled. But when updating, the value being passed in to my format function is vbNull instead of the value in the phone number field of the control. How can I get the update...
1
1222
by: Marko Loukkaanhuhta | last post by:
Hi, this might be newbies question, but hey I'm newbie.. I'm trying to make a web site which you can use to read and update data from sql server. Data on the sql server is text. Data fields in sql server are ntext type. Ok, I've managed to read data and update data to the sql server from my website, however even if my text contains (at least in the sql server and in edit box) carriage returns, like paragraphs made by return key, like...
0
1249
by: Seok Bee | last post by:
Dear Experts, In my web application, I have a Master/Detail display of records using Gridview and DetailsView controls. Whenever, I made a selection of a record from the Gridview control, the detail information of the record will be displayed in the DetailsView control. Information in the editable in the detailsview by allowing user to have the edit option. On top of that I also allow user to add new record through the detailsview...
0
1990
by: Marek | last post by:
I have DetialsView control and DropDownList control on the same page. I use DropDownList.SelectedVlue as key for DetailsView control. I use SELECT ... FROM table WHERE id_kont = @id_kont where @id_kont is equal DropDownList.SelectedValue and it is work. But when I try to do (for DetailsView control): INSERT INTO table (id_kont,....) VALUES ( @id_kont,....)
0
1000
by: Luke Graham | last post by:
hi, I'm coding a social network style application for my dissertation and am having a few problems, I'm using ASP.net and VB.net I have a button within a DetailsView control that I want to trigger an Insert for a Datasource that is also within the DetailsView There is an OnClick event handler for the button but I'm having problems finding the datasource to trigger it the code I'm using is Dim DataSource As SqlDataSource =...
1
1779
by: miconib | last post by:
Hello everyone. I am not really a databse pro like most of you here, but i did make a small access database for our warehouse to scan serial numbers into the system. I have a few questions if anyone could help me it would be great. 1st Most of our products come on a palet and they are able to scan each one. Sometime we get a box or palet that has a two and from barcode. Is there anyway i can create some type of VB script which will allow...
3
2767
by: =?Utf-8?B?QW5nZWw=?= | last post by:
I seem to understand how the control works as long as I mated to SqlDataSource or ObjDataSource it works fine. But I do not want to flatten my design in this manner. I am interested in how I can programmatically manipulate the control. In other words maybe just use the data source then extract from the control the information do with it as I see fit. The opposite is also true. I want to be able to add or modify the data in the...
0
2217
by: =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= | last post by:
In VS2008, I have a DetailsView control with a checkboxlist control inside its Edit template. (1) I want the checkboxlist to be dynamic and display only as many checkboxes as a user setting is configured. How? (2) Also the column that should depict the checkboxlist selections, is a simple character column in SSE2005, in the form of a comma-delimited string (e.g. 1,5,7,12,23). When the DetailsView is loaded, I want each of the...
0
10793
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
10510
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
10548
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
9331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7758
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
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
5794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.