0

I have a dropdownlist which gets the data from a database table(emptyseats). I select an item (seat) from this dropdownlist and save it in a different table (occupiedseats).After this i want to delete the seat from the first table (emptyseats) to show that it is now occupied. My problem is the seat is only removed from the dropdownlist not the database, so this makes it available when i re-run the program. Moreover i want to re-bind the dropdownlist with the previously selected seat not included. Can someone point me in the right direction.

DropDownList1.Items.Remove(DropDownList1.SelectedItem);//im stuck with this

Thanks!

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by tlox
1

I have a dropdownlist which gets the data from a database table(emptyseats). I select an item (seat) from this dropdownlist and save it in a different table (occupiedseats).After this i want to delete the seat from the first table (emptyseats) to show that it is now occupied. My problem is the seat is only removed from the dropdownlist not the database, so this makes it available when i re-run the program. Moreover i want to re-bind the dropdownlist with the previously selected seat not included. Can someone point me in the right direction.

DropDownList1.Items.Remove(DropDownList1.SelectedItem);//im stuck with this

Thanks!

Hello,

Good morning

you can eliminate the registry Remove DropDownList1 used that method, but what about your not referencing anything with the database, let me give you an ide of how you can do.

Step 2 call function

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

        Dim resultado As Integer = DeleteElements(DropDownList1.SelectedValue)
        If resultado > 0 Then

            DropDownList1.Items.Remove(resultado)

        Else

        End If
    End Sub

Step 1 Step 2 added a feature to you the true or false devuleve elimination

 Dim resultado As Integer
    Public Function DeleteElements(ByVal ID As Integer) As Integer

        Using cn As New SqlConnection("conection")

            Dim Delete As String = "Delete From tabla where ID = @ID"
            Dim cmd As New SqlCommand(Delete, cn)
            cmd.Parameters.AddWithValue("@ID", ID)
            cn.Open()

            Try

                resultado = cmd.ExecuteNonQuery()

            Catch ex As Exception

            Finally

                cn.Close()
            End Try

        End Using

        Return resultado

    End Function

greetings

Edited by __avd: Added [code]..[/code] tags.

0

Thank you. I got the idea.

Hello,

Good morning

you can eliminate the registry Remove DropDownList1 used that method, but what about your not referencing anything with the database, let me give you an ide of how you can do.

Step 2 call function

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

Dim resultado As Integer = DeleteElements(DropDownList1.SelectedValue)
If resultado > 0 Then

DropDownList1.Items.Remove(resultado)

Else

End If
End Sub

Step 1 Step 2 added a feature to you the true or false devuleve elimination

Dim resultado As Integer
Public Function DeleteElements(ByVal ID As Integer) As Integer

Using cn As New SqlConnection("conection")

Dim Delete As String = "Delete From tabla where ID = @ID"
Dim cmd As New SqlCommand(Delete, cn)
cmd.Parameters.AddWithValue("@ID", ID)
cn.Open()

Try

resultado = cmd.ExecuteNonQuery()

Catch ex As Exception

Finally

cn.Close()
End Try

End Using

Return resultado

End Function


greetings

This topic has been dead for over six months. 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.