Solved

Loading SQL results into grid headers

Posted on 2012-03-22
2
414 Views
Last Modified: 2012-03-23
Hi Experts,

I am using the attached code to grab a list of suppliers. With the code I have it loads the results horizontally into the left most cells, I would like these to go across the top of Row1 as column names. Is this possible? Im thinking I may have to load them into an array and then loop thru the array inserting into the grid?

  Private Sub LoadSuppliers()
        Dim LoadVendorconn As New SqlConnection("")
        Dim LoadVendorstrSQL As String = "SELECT * FROM  Suppliers ORDER BY Supplier"
        Dim LoadVendorda As New SqlDataAdapter(LoadVendorstrSQL, LoadVendorconn)
        Dim LoadVendordt1 As New DataTable

        LoadVendorconn.Open() 'Open the connection

        LoadVendorda.Fill(LoadVendordt1)

        Dim NewArray As String = LoadVendorda

        With FlxRtv
            .DataSource = LoadVendordt1
        End With



Thanks,
Dean
0
Comment
Question by:deanlee17
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
VBClassicGuy earned 500 total points
ID: 37753832
If you're using a FlexGrid, which your variable of "FlxRtv" leads me to believe, each row of values needs to be seperated by a tab character. With an unbound FlexGrid, you could do something like this (assume "rs" is the returned recordset from your Select query):

Dim txt As String

While Not rs.EOF
   If Len(txt) Then
      txt = txt & vbTab & rs.Supplier
   Else
      txt = rs.Supplier
   End If
Wend

FlxRtv.AddItem txt
0
 
LVL 4

Expert Comment

by:frankd
ID: 37753853
Here is code I use to populate the Header row with different text, it may be what you're looking for.

DataGridView1.Columns(HeaderText).HeaderText = "Station " & Str(e.ColumnIndex - 1) & " On"
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question