VB6, Databases, and DataGrids!
-
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
-
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
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.