0

Hi!

I'm using Microsoft Visual Studio 2008, Microsoft SQL Server Management Studio.
I need help. I cant figure out this if else statement for this condition:

                ///to check condition either the way ID exist in database
                ///if not exist then way ID can be delete
                ///if exist, message box appear show message this cannot be delete

My code was be like this.

Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim i As Integer
        Dim iResult As Integer
        Dim hypWayID As HyperLink
        Dim chkRemove As New CheckBox
        Dim clsWay As New Way()

        Try

            For i = 0 To grdWay.Rows.Count - 1
                chkRemove = DirectCast(grdWay.Rows(i).FindControl("chkRemove"), CheckBox)
                hypRouteID = DirectCast(grdWay.Rows(i).FindControl("hypWayID"), HyperLink)

                If chkRemove.Checked Then



                    ///to check condition either the way ID exist in database
                    ///if not exist then way ID can be delete
                    ///if exist, message box appear show message this cannot be delete



                    iResult = clsWay.DeleteRoute(hypWayID.Text)
                End If
            Next i
            labelError.Text = "Item(s) delete successfully."
            BindGrid("%", "%", drpArea.SelectedValue,drpType.SelectedValue)
        Catch ex As Exception
            lblError.Text = ex.Message
        End Try

    End Sub

Anyone can help me? :(

2
Contributors
4
Replies
19
Views
2 Years
Discussion Span
Last Post by nimz143
0

to check condition either the way ID exist in database
if not exist then way ID can be delete
if exist, message box appear show message this cannot be delete

Do you mean if it has foreign keys attached? If so, you can try to delete and it will trigger an exception if the record is still referenced (unless you have DELETE CASCADE enabled).

0

No, it dont have foreign key. How to solve this just by using the option that i had told it, pritaeas?

0

Execute a query that searches for your ID (I don't know which table you want to search), and if it returns a record, then it exists.

0

Hi pritaeas :)

I'm able to solve this. I'm using this query

SELECT M_C FROM [dbo].[TPATH]
WHERE M_C IN (SELECT M_C FROM [dbo].[TTENS])
and M_C = @M_C

and its also working by using this query

SELECT M_C FROM [dbo].[TPATH]
except
SELECT M_C FROM [dbo].[TTENS]

Thanks for your help =')

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.