Link to home
Start Free TrialLog in
Avatar of mgordon-spi
mgordon-spi

asked on

Manually add archived rows to dropdown if needed for selection

I have 2 subs. The first one populates the dropdown list. The second selects a value in the list.

Rows for the dropdown have been archived and don't get populated in the list. But if they are in the second sub to be selected, I need to be able to add that value back into the list for selection
Sub : 1 

        Dim sExternal As String = "SELECT * FROM tBOSTypes WHERE sCategory = @sCategory AND Archive = @Archive Order By sItem"
        Dim daExternal As New SqlClient.SqlDataAdapter(sExternal, myUtility.sqlConn)
        daExternal.SelectCommand.Parameters.AddWithValue("@sCategory", "External Wall Material")
        daExternal.SelectCommand.Parameters.AddWithValue("@Archive", False)
        Dim dtExternal As New DataTable
        daExternal.Fill(dtExternal)
        Dim newCustomersRow As DataRow = dtExternal.NewRow()
        newCustomersRow("ID") = "0"
        newCustomersRow("sItem") = "Select Wall Type..."
        dtExternal.Rows.InsertAt(newCustomersRow, 0)
        cboExternal.DataSource = dtExternal
        cboExternal.DisplayMember = "sItem"
        cboExternal.ValueMember = "ID"

Sub : 2

        Dim sWall As String = "SELECT     tBOSItems.BOSTypeID, tBOSTypes.sCategory, tBOSTypes.sItem, tBOSItems.ProjectID, tBOSTypes.ID " & _
                           "FROM         tBOSTypes INNER JOIN " & _
                                       "tBOSItems ON tBOSTypes.ID = tBOSItems.BOSTypeID " & _
                           "WHERE     (tBOSItems.ProjectID = @ProjectID) AND sCategory = @Type"
        Dim daWall As New SqlClient.SqlCommand(sWall, myUtility.sqlConn)
        Dim dtWall As New DataTable
        daWall.Parameters.AddWithValue("@ProjectID", ContainerForm.ProjectID)
        daWall.Parameters.AddWithValue("@Type", "External Wall Material")
        myUtility.sqlConn.Open()
        WallID = daWall.ExecuteScalar
        myUtility.sqlConn.Close()
        cboExternal.SelectedValue = WallID

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial