Results 1 to 2 of 2

Thread: Having trouble weith the DataGrid

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Posts
    17
    I have been using the datagrid with ADO, but I want to use the datagrid to add to an empty table, my problem is how do I set up the columns so that the column headings are the field names? I keep getting a rowset error.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    If you are using SQL Server you can use the syscolumns table to be able to generate a list of the columns for the table in question and use that information to populate the column headers.

    Code:
    SELECT sc.Name as ColumnName
    FROM   sysobjects so LEFT JOIN syscolumns sc ON so.Id = sc.Id
    WHERE  so.Type = 'U'
    AND    so.Name = '<Insert Table Name Here>'
    This gives you a list of the fields in the table. If you want to get REALLY smart you can include the datatype into the statement, connect to the systypes table and also determine the width each field needs to be to display ALL the data... but that would triple the complexity of the query

    Your alternative is to open a recordset.

    Code:
    Dim iField as Integer
    Dim sMsg as String
    
    Set rstTemp = db.OpenRecordset("TableName",dbOpenSnapshot, dbReadOnly, dbReadOnly)
    
    For iField = 1 to rstTemp.Fields.Count
       sMsg = sMsg & "Field called " & rstTemp.Fields(iField).Name & vbCR
    
       < You can assign to the header of this column here>
    
    Next iField
    
    MsgBox sMsg
    See how that goes

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