Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Manually add archived rows to dropdown if needed for selection

Posted on 2011-10-03
1
Medium Priority
?
161 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:mgordon-spi
1 Comment
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 36909925
You can retrieve both the value and text and then use FindString/FindStringExact method to see if it exists in the list and add if not.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question