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!

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

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

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.