+ Post New Thread
Results 1 to 9 of 9
Coding Thread, Creating query based on multiple combo boxes in Coding and Web Development; Hi there. I have a form with 3 combo boxes on, each with a random number of items in them. ...
  1. #1
    Shrimpersfan's Avatar
    Join Date
    Feb 2008
    Location
    Peterborough
    Posts
    52
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Creating query based on multiple combo boxes

    Hi there.

    I have a form with 3 combo boxes on, each with a random number of items in them.

    What I am trying to do is to let the user select items from the combo boxes and then generate the sql query based on what they had selected, i would then want to display the results of this query in a datagrid view.

    I am fairly sure i will need to use a sproc to pass parameters for the fields i will need from the app to the database but i am pretty much a vb novice and have only recently started using sql connections through it.

    Any help would be greatly appreciated.

  2. #2

    Join Date
    Apr 2008
    Posts
    853
    Thank Post
    111
    Thanked 112 Times in 108 Posts
    Rep Power
    45
    I know how to do it but building new IT suite at the moment so will get back to you later, PM me (After work)

  3. #3
    sahmeepee's Avatar
    Join Date
    Oct 2005
    Location
    Greater Manchester
    Posts
    795
    Thank Post
    20
    Thanked 70 Times in 42 Posts
    Rep Power
    34
    Are you making a windows application in VB or a web-based asp/asp.net app in vbscript/vb.net?

  4. #4
    Shrimpersfan's Avatar
    Join Date
    Feb 2008
    Location
    Peterborough
    Posts
    52
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I am making a windows app in vb.net and am using ADO.net for my sql connections.

  5. #5

    Join Date
    Apr 2008
    Posts
    853
    Thank Post
    111
    Thanked 112 Times in 108 Posts
    Rep Power
    45
    oh.... I only know how to do it with asp.net with VB.net

  6. #6
    Jay
    Jay is offline

    Join Date
    Mar 2008
    Location
    Autocratic theocracy of Norfolk
    Posts
    71
    Thank Post
    3
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    Try something like the below and bind to a gridview/datagrid.

    (from memory, so untested)

    Function getFoo() As DataSet

    Dim ds As New DataSet

    Dim oConn As New SqlConnection(System.Configuration.ConfigurationMa nager.ConnectionStrings("Foo_Connection").Connecti onString)

    Dim oComm As New SqlCommand
    With oComm
    .Connection = oConn
    .CommandText = "FooDB.dbo.sp_Get_My_Foo"
    .CommandType = CommandType.StoredProcedure
    End With

    oComm.Parameters.Add("@Param1", Data.SqlDbType.NVarChar).Value = sParam1
    oComm.Parameters.Add("@Param2", Data.SqlDbType.NVarChar).Value = sParam2
    oComm.Parameters.Add("@Param3", Data.SqlDbType.NVarChar).Value = sParam3

    Dim DA As New SqlDataAdapter(oComm)
    Try
    DA.Fill(ds)
    Catch ex As Exception
    Throw
    Return Nothing
    Finally
    If Not (oConn.State = ConnectionState.Closed) Then oConn.Dispose()
    End Try

    Return ds
    End Function

  7. #7
    Shrimpersfan's Avatar
    Join Date
    Feb 2008
    Location
    Peterborough
    Posts
    52
    Thank Post
    9
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks Jay.

    I can see how this may work. How would i get the results of the sproc to appear in a datagrid view?

  8. #8

    Join Date
    May 2008
    Location
    Cheshire
    Posts
    292
    Thank Post
    48
    Thanked 27 Times in 24 Posts
    Rep Power
    18
    Quote Originally Posted by Shrimpersfan View Post
    Thanks Jay.

    I can see how this may work. How would i get the results of the sproc to appear in a datagrid view?
    I think the datagrid view can do a .requery?

  9. #9
    Jay
    Jay is offline

    Join Date
    Mar 2008
    Location
    Autocratic theocracy of Norfolk
    Posts
    71
    Thank Post
    3
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    GridView.DataSource = getFoo()
    GridView.DataBind()


    Normally I would pop the above in some sort of function I can call whenever I need to refresh the contents of the gridview. That way I can either:

    1) Implement some custom paging/sorting/searching etc using parameters to only present the results I want back from the database.

    2) I can use the built in (dot net 2) paging/sorting/searching functions without going back to the database at all at the cost of a larger initial query (entire results set) .

    With both appropaches you have to get the data back from the database once its been changed. (particularly in a multi-user system)

SHARE:
+ Post New Thread

Similar Threads

  1. IWB Control Boxes/Trunking Boxes?
    By dbsocs08 in forum Hardware
    Replies: 6
    Last Post: 12th December 2008, 06:46 PM
  2. Exchange 2003 - Query Based Distribution Group
    By MattGibson in forum Windows
    Replies: 0
    Last Post: 17th November 2008, 02:15 PM
  3. DVD/VHS combo - any ones stand out?
    By rhyds in forum Hardware
    Replies: 1
    Last Post: 6th November 2007, 10:39 AM
  4. SIS 900 LAN and Group Policy = BAD COMBO! Help!
    By CM786 in forum Wireless Networks
    Replies: 19
    Last Post: 6th August 2006, 07:20 AM
  5. Creating web based word searchs
    By Quackers in forum Web Development
    Replies: 6
    Last Post: 27th June 2006, 02:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •