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_groep1". 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:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" runat="server"
CommandArgument="<%# Container.DataItemIndex %>"
CommandName="Delete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
....
code-behind:
-----------
....
If e.CommandName = "Delete" Then
Try
Me.SqlDataSource1.DeleteCommand = "delete from groep WHERE groepnr='" &
groupkey & "'"
Catch ex As Exception
label1.Text = "Group '" & Server.HtmlEncode(groupkey) & "' cannot be
removed."
End Try
End If
Thanks
Vincent
T. 2 1646
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.DataSource = SqlDataSource1
try
GridView1.DataBind()
catch
....
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin http://usableasp.net
"Vincent" <vi,@sd.cvwrote in message
news:eu**************@TK2MSFTNGP04.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_groep1". 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:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" runat="server"
CommandArgument="<%# Container.DataItemIndex %>"
CommandName="Delete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
...
code-behind:
-----------
...
If e.CommandName = "Delete" Then
Try
Me.SqlDataSource1.DeleteCommand = "delete from groep WHERE groepnr='" &
groupkey & "'"
Catch ex As Exception
label1.Text = "Group '" & Server.HtmlEncode(groupkey) & "' cannot be
removed."
End Try
End If
Thanks
Vincent
T.
Thanks
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgschree f in
bericht news:eD**************@TK2MSFTNGP02.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.DataSource = SqlDataSource1
try
GridView1.DataBind()
catch
...
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin http://usableasp.net
"Vincent" <vi,@sd.cvwrote in message
news:eu**************@TK2MSFTNGP04.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_groep1". 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:GridView ID="GridView1" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="lb1" runat="server" CommandArgument="<%# Container.DataItemIndex %>" CommandName="Delete"> </asp:LinkButton> </ItemTemplate> </asp:TemplateField> ...
code-behind: ----------- ... If e.CommandName = "Delete" Then Try Me.SqlDataSource1.DeleteCommand = "delete from groep WHERE groepnr='" & groupkey & "'" Catch ex As Exception label1.Text = "Group '" & Server.HtmlEncode(groupkey) & "' cannot be removed." End Try End If
Thanks Vincent
T.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |