Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB6, Databases, and DataGrids!

VB6, Databases, and DataGrids!

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matt T
    wrote on last edited by
    #1

    Hi, I have connected a database to a DataGrid in VB6, but I need to do 2 things with it. 1, I want to sort the database alphabetically by a certain field, before it is displayed in the DataGrid. I have tried using some SQL but it doesnt like it. Does anyone know how to do this, or if there is a specific 'Reference' or 'Component' which needs adding? I can add, amend and delete records from the database, I just cant sort it! Here is code I am using to connect to the database and table: Dim strQ As String strQ = "DRIVER={Microsoft Access Driver (*.mdb)};" & _ "DBQ=" & App.Path & "\lottery.mdb" cnControls.Open strQ rsControls.Open "syndicate1", cnControls, adOpenKeyset, adLockOptimistic Set grdControls.DataSource = rsControls 2, The second problem I have, is with the display of the DataGrid in VB. The database table is automatically read into the DataGrid, and I want to customize the width of the 'fields' of the DataGrid. Does anyone know how to do this? At present, some columns are too narrow or wide for the data being displayed. Because of this, some field names arent fully visible. Any help will be greatly appreciated, Many Thanks, Matt

    L 1 Reply Last reply
    0
    • M Matt T

      Hi, I have connected a database to a DataGrid in VB6, but I need to do 2 things with it. 1, I want to sort the database alphabetically by a certain field, before it is displayed in the DataGrid. I have tried using some SQL but it doesnt like it. Does anyone know how to do this, or if there is a specific 'Reference' or 'Component' which needs adding? I can add, amend and delete records from the database, I just cant sort it! Here is code I am using to connect to the database and table: Dim strQ As String strQ = "DRIVER={Microsoft Access Driver (*.mdb)};" & _ "DBQ=" & App.Path & "\lottery.mdb" cnControls.Open strQ rsControls.Open "syndicate1", cnControls, adOpenKeyset, adLockOptimistic Set grdControls.DataSource = rsControls 2, The second problem I have, is with the display of the DataGrid in VB. The database table is automatically read into the DataGrid, and I want to customize the width of the 'fields' of the DataGrid. Does anyone know how to do this? At present, some columns are too narrow or wide for the data being displayed. Because of this, some field names arent fully visible. Any help will be greatly appreciated, Many Thanks, Matt

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      question 1) You can use the sort method of the rs object. SQl should work as well. rsControls.sort= "lname DESC, fname ASC" or rsControls.Open "select * from syndicate1 order by syndicate1.lname ASC", cnControls, adOpenKeyset, adLockOptimistic question 2) I belive you are looking for the datagrid.defcolwidth property.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups