473,811 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to show my own error message?

Hi,

There are two related tables: one called 'group' and the other 'items'. Each
item belongs to a group. The table 'group' is shown in a gridview with a
linkbutton for deleting.

When an user tries to delete a group which still contains items, he gets the
message:
"The DELETE statement conflicted with the REFERENCE constraint
"FK_items_groep 1". The conflict occurred in database "tennis", table
"dbo.mytabl e", column 'groupna'.
The statement has been terminated. "

I want to avoid this and just send a short message in a label. So i tried
this, but the error message still appears.

aspx file:
----------
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" runat="server"
CommandArgument ="<%# Container.DataI temIndex %>"
CommandName="De lete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
....

code-behind:
-----------
....
If e.CommandName = "Delete" Then
Try
Me.SqlDataSourc e1.DeleteComman d = "delete from groep WHERE groepnr='" &
groupkey & "'"
Catch ex As Exception
label1.Text = "Group '" & Server.HtmlEnco de(groupkey) & "' cannot be
removed."
End Try
End If
Thanks
Vincent

T.
Feb 19 '08 #1
2 1664
You need to try-catch the databind operation. With the declarative
databinding it is a bit tricky. It will be simpler just to use regular
databinding, with the DataSource property rather that with the DataSourceID:

GridView1.DataS ource = SqlDataSource1
try
GridView1.DataB ind()
catch
....
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Vincent" <vi,@sd.cvwro te in message
news:eu******** ******@TK2MSFTN GP04.phx.gbl...
Hi,

There are two related tables: one called 'group' and the other 'items'.
Each item belongs to a group. The table 'group' is shown in a gridview
with a linkbutton for deleting.

When an user tries to delete a group which still contains items, he gets
the message:
"The DELETE statement conflicted with the REFERENCE constraint
"FK_items_groep 1". The conflict occurred in database "tennis", table
"dbo.mytabl e", column 'groupna'.
The statement has been terminated. "

I want to avoid this and just send a short message in a label. So i tried
this, but the error message still appears.

aspx file:
----------
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" runat="server"
CommandArgument ="<%# Container.DataI temIndex %>"
CommandName="De lete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
...

code-behind:
-----------
...
If e.CommandName = "Delete" Then
Try
Me.SqlDataSourc e1.DeleteComman d = "delete from groep WHERE groepnr='" &
groupkey & "'"
Catch ex As Exception
label1.Text = "Group '" & Server.HtmlEnco de(groupkey) & "' cannot be
removed."
End Try
End If
Thanks
Vincent

T.


Feb 19 '08 #2
Thanks
"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgsch reef in
bericht news:eD******** ******@TK2MSFTN GP02.phx.gbl...
You need to try-catch the databind operation. With the declarative
databinding it is a bit tricky. It will be simpler just to use regular
databinding, with the DataSource property rather that with the
DataSourceID:

GridView1.DataS ource = SqlDataSource1
try
GridView1.DataB ind()
catch
...
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Vincent" <vi,@sd.cvwro te in message
news:eu******** ******@TK2MSFTN GP04.phx.gbl...
>Hi,

There are two related tables: one called 'group' and the other 'items'.
Each item belongs to a group. The table 'group' is shown in a gridview
with a linkbutton for deleting.

When an user tries to delete a group which still contains items, he gets
the message:
"The DELETE statement conflicted with the REFERENCE constraint
"FK_items_groe p1". The conflict occurred in database "tennis", table
"dbo.mytable ", column 'groupna'.
The statement has been terminated. "

I want to avoid this and just send a short message in a label. So i tried
this, but the error message still appears.

aspx file:
----------
<asp:GridVie w ID="GridView1" runat="server">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" runat="server"
CommandArgument ="<%# Container.DataI temIndex %>"
CommandName="De lete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
...

code-behind:
-----------
...
If e.CommandName = "Delete" Then
Try
Me.SqlDataSourc e1.DeleteComman d = "delete from groep WHERE groepnr='" &
groupkey & "'"
Catch ex As Exception
label1.Text = "Group '" & Server.HtmlEnco de(groupkey) & "' cannot be
removed."
End Try
End If
Thanks
Vincent

T.



Feb 19 '08 #3

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

Similar topics

13
74148
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide Form1.Visible = False Load (Form1)
4
10949
by: Drew Lettington | last post by:
I'm making a simple call to display error messages in a MessageBox from a Windows form and the MessageBox is not behaving in a modal fashion. My modal form displays, the user clicks a button and error handling code calls MessageBox.Show. The user is then allowed to click the button on my form again before clicking OK on the MessageBox. Any ideas why the MessageBox is not behaving modally?
14
20400
by: Ina Schmitz | last post by:
Hello all, I don't succeed in displaying the explain plan. I use IBM DB2 Universal Database 8.2. I tried to do the example given in the online help for "Visual Explain". The tables EXPLAIN_STATEMENT and EXPLAIN_INSTANCE exist. With VESAMPL.DDL, I loaded the predefined execution plans. In the next step, I'ld like to display the loaded access plans. So, I right clicked on "Show Explained Statements History" and got the result:
7
16978
by: Bill | last post by:
For some reason, I have an errormessage popup that "blinks", but pops up BEHIND the applications, which is confusing to users. Is there any way to force it to the top?
2
4479
by: Dave | last post by:
Hi, I am writing a c# application that using a directshow to play file and display it on my C# gui, its work just fine but when i try to open another thread in my c# application the file stop playing and i get black image!!! Why? What i should considre when i open a new thread in c# application?? Thanks
3
3990
by: Ipsita | last post by:
Hi, I am explaining the scenario of what I am trying to do: - I have a webform with some controls, from which I am taking the data. eg say Username, password - I am passing these data as parameters to the web service method result = serviceproxy.VerifyUser(username, password) on the event of the "Submit" button_click. - The webservice webmethod uses the username, password to verify if the user is valid user. If no, it sends an error...
5
3597
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle...
8
7840
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle "http://msdn.microsoft.com/library/default.asp?url=/library/en-...
1
2517
by: runway27 | last post by:
hi I am using MySQL - 4.1.22 when i use the following sql query $result = mysql_query("SHOW tablename STATUS FROM databasename;"); i have also tried = $result = mysql_query("SHOW tablename STATUS FROM databasename"); i get the following error message ====================================================
2
11537
by: Sudhakar | last post by:
hi I am using MySQL - 4.1.22 when i use the following sql query $result = mysql_query("SHOW tablename STATUS FROM databasename;"); i have also tried = $result = mysql_query("SHOW tablename STATUS FROM databasename"); i get the following error message
0
9734
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
9607
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
10652
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
10137
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
9211
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...
0
6895
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
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3026
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.