Results 1 to 7 of 7

Thread: How to show less columns then selected with SQL?

  1. #1

    Thread Starter
    Lively Member WiseGuy's Avatar
    Join Date
    Apr 2002
    Location
    Zierikzee, The Netherlands
    Posts
    98

    How to show less columns then selected with SQL?

    Allright here's the situation,

    I've made a huge SQL statement to select and Join a few tables, but I only want to show 5 of them in my grid. I'm using ADO fully in code and a MSHFlexGrid as grid. Here's my code:

    VB Code:
    1. Dim strSQL As String
    2.  
    3.   Set cn = New ADODB.Connection
    4.   cn.ConnectionString = "Data Source=spijsDB;User ID=spijs;Password=spijs;"
    5.   cn.Open
    6.   Set rs = New ADODB.Recordset
    7.   grdDatagrid.Refresh
    8.   cn.CursorLocation = adUseServer
    9.   strSQL = "Select c.celid,c.celnaam,c.celtypeid,ct.celtypenaam,c.artikelid," & _
    10.            "a.artikelnaam, TO_CHAR(a.natdroogverh),c.geblokkeerdaanvoer,c.geblokkeerdafvoer," & _
    11.            "TO_CHAR(c.fijn1kg), TO_CHAR(c.fijn2kg), TO_CHAR(c.grofkg), TO_CHAR(c.continuekg), " & _
    12.            "TO_CHAR(c.navalkg), TO_CHAR(c.soortelijkemassa)," & _
    13.            "c.wegerid,c.plccelcode, TO_CHAR(c.voorraadkg),c.lijnid,l.lijncode " & _
    14.            "From cellen c, lijnen l, celtype ct, artikelen a " & _
    15.            "where c.lijnid = l.lijnid(+) " & _
    16.            "and c.celtypeid = ct.celtypeid " & _
    17.            "and c.artikelid = a.artikelid(+)" & _
    18.            "Order by to_number(c.celid)"
    19.            
    20.   rs.Open strSQL, cn
    21.   Set grdDatagrid.DataSource = rs
    22.   grdDatagrid.Refresh
    23.   grdDatagrid.TextMatrix(0, 1) = "Nummer"
    24.   grdDatagrid.TextMatrix(0, 2) = "Naam"
    25.   grdDatagrid.TextMatrix(0, 3) = "Type"
    26.   grdDatagrid.TextMatrix(0, 4) = "Artikel"
    27.   grdDatagrid.TextMatrix(0, 5) = "Naam"

    And the only columns I want to show are c.CellID, c.Celnaam, ct.celtypenaam, c.artikelID and a.artikelnaam

    Is that possible or do I have to make a new statement with only the columns I want to show in the grid?


    WiseGuy
    I stuck my head out of the window and got arrested for mooning!

    This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
    O/S: Windows XP Professional (dutch)
    Internet: Cable (1Mbit connection)

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Have a look at Flexgrid.ColWidth(<column number>) = 0

    You need to set the column width to 0 to hide the column(s). Note that the first column is 0 (like arrays).


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Even though you're hiding the column, doesn't that still imply you're retrieving the fields from the database?

    Why don't you retrieve ONLY the five fields you want?

  4. #4

    Thread Starter
    Lively Member WiseGuy's Avatar
    Join Date
    Apr 2002
    Location
    Zierikzee, The Netherlands
    Posts
    98
    Becouse I need the other fields to fill in some other stuff on the form.
    But I'm not quite sure how I'm gonna do that so I wanted to try it this
    way first. And I think this is a good solution!

    Sometimes solutions are so easy that you just can't think of them


    Thanks,

    WiseGuy
    I stuck my head out of the window and got arrested for mooning!

    This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
    O/S: Windows XP Professional (dutch)
    Internet: Cable (1Mbit connection)

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Then that's the way to go....

    uhm...

  6. #6
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Mendhak - its to save calling the db twice. First call would be for the list to select the second call to retrieve the data. But if you shove all the data you need into the grid and hide it you only need one call to the db reducing network connections and 'seemingly' increase the response speed

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  7. #7

    Thread Starter
    Lively Member WiseGuy's Avatar
    Join Date
    Apr 2002
    Location
    Zierikzee, The Netherlands
    Posts
    98
    Wow that's exactly what I thought!


    WiseGuy
    I stuck my head out of the window and got arrested for mooning!

    This Post is sponsored by my PC: PIII900, 512MBDimm/133, Seagate 40GB/7200 ATA100, LiteOn 12x DVD, Lite-On 32x12x40 CDrw, Elsa Geforce2 Ultra 64MB incl tv-out, SoundBlaster Live 1024, Ilyama A702HT Vision Master Pro410 17".
    O/S: Windows XP Professional (dutch)
    Internet: Cable (1Mbit connection)

Posting Permissions

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



Click Here to Expand Forum to Full Width