Solved

Loading SQL results into grid headers

Posted on 2012-03-22
2
400 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now