473,785 Members | 3,214 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 3127
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
1159
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
3368
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
1221
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
1248
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
1989
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
1775
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
2765
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
2214
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
9643
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
9480
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
10147
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...
0
9947
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
6737
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
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.