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? :(

Recommended Answers

All 4 Replies

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).

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

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.

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 =')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.