Solved

Loading SQL results into grid headers

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

Technology Partners: 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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

628 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