CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic .NET
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual Basic .NET Microsoft Visual Basic .NET and related questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 1st, 2009, 10:07 PM
    newcoder83 newcoder83 is offline
    Junior Member
     
    Join Date: Sep 2009
    Posts: 16
    newcoder83 is an unknown quantity at this point (<10)
    [RESOLVED] Urgent-how to set criteria for SQL query using combobox

    Hi all, needed help to set the selection criteria using combobox, but there is a possibility to select "All Items" option. There are more than 2 combobox selection. Really need advise...
    Code:
    strSQL = "SELECT nama from GridView"
            Dim da As New SqlDataAdapter(strSQL, oconnection)
            Dim ds As New DataSet
            da.Fill(ds, "name")
            Dim dt As New DataTable
            'dt = ds.Tables(0)
    
            dt.Columns.Add("name", GetType(System.String))
            Dim drDSRow As DataRow
            Dim drNewRow As DataRow
    
            dt.Rows.Add("*", "All names") ---->just the toppest row that needed the selected value
    
            For Each drDSRow In ds.Tables("name").Rows()
                drNewRow = dt.NewRow
                drNewRow("name") = drDSRow("name")
                dt.Rows.Add(drNewRow)
            Next
    
    
            ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
    
            With ComboBox1
                .DataSource = dt
                .DisplayMember = "nama"
                '.SelectedIndex = 0
    
            End With

    Last edited by newcoder83; November 1st, 2009 at 11:14 PM. Reason: complete the thread
    Reply With Quote
      #2    
    Old November 2nd, 2009, 10:12 AM
    HanneSThEGreaT's Avatar
    HanneSThEGreaT HanneSThEGreaT is online now
    The Moody Mod
    Power Poster
     
    Join Date: Jul 2001
    Location: Vereeniging, South Africa
    Posts: 7,685
    HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)HanneSThEGreaT has a reputation beyond repute (3000+)
    Re: Urgent-how to set criteria for SQL query using combobox

    is this resolved or what ¿
    __________________
    My Latest Articles :
    VB and Internet Explorer Browsing History || The TaskBar and VB.NET || Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005
    Find All My Articles : Here

    FAQs :
    .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs

    Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1

    Read This Before You Post || Acceptable Use Policy
    Reply With Quote
      #3    
    Old November 7th, 2009, 06:04 AM
    newcoder83 newcoder83 is offline
    Junior Member
     
    Join Date: Sep 2009
    Posts: 16
    newcoder83 is an unknown quantity at this point (<10)
    Smile Re: Urgent-how to set criteria for SQL query using combobox

    sorry for late respond, i have resolved it. this is the code.
    Code:
    strSQL1 = " SELECT DISTINCT(ACC) FROM " & Trim(deptGStbl) & " WHERE PT ='" & Trim(cbPT.SelectedValue.ToString) & "'"
            If cbPT.SelectedIndex = 0 Then
                strSQL1 = strSQL1.Replace("=", " like ")
            End If
            strSQL2 = " AND KDST ='" & Trim(cbKDST.SelectedValue.ToString) & "'"
            If cbKDST.SelectedIndex = 0 Then
                strSQL2 = strSQL2.Replace("=", " like ")
            End If
            strSQL3 = " AND KDKB='" & Trim(cbKDKB.SelectedValue.ToString) & "'"
            If cbKDKB.SelectedIndex = 0 Then
                strSQL3 = strSQL3.Replace("=", " like ")
            End If
            strSQL = strSQL1 & strSQL2 & strSQL3
    
    
    
    
            Dim dacbAccGS As New SqlDataAdapter()
            dacbAccGS.SelectCommand = New SqlCommand(strSQL, oconnection)
            ' Create DataSet, fill it and view in data grid
            Dim dscbAccGS As New DataSet
            dacbAccGS.Fill(dscbAccGS, "acc")
            Dim dtcbAccGS As New DataTable
    
            dtcbAccGS.Columns.Add("account", GetType(System.String))
            dtcbAccGS.Columns.Add("value", GetType(System.String))
            Dim drDSRow As DataRow
            Dim drNewRow As DataRow
    
            drNewRow = dtcbAccGS.NewRow
            drNewRow("account") = "All Account"
            drNewRow("value") = "%"
            dtcbAccGS.Rows.Add(drNewRow)
    
            For Each drDSRow In dscbAccGS.Tables("acc").Rows()
                drNewRow = dtcbAccGS.NewRow
                drNewRow("account") = drDSRow("acc")
                drNewRow("value") = drDSRow("acc")
                dtcbAccGS.Rows.Add(drNewRow)
            Next
    
    
            cbAccount.DropDownStyle = ComboBoxStyle.DropDownList
    
            With cbAccount
                .DataSource = dtcbAccGS
                .DisplayMember = "account"
                .ValueMember = "value"
                '.SelectedIndex = 0
    
            End With
    Thank you
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic .NET


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 05:22 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009