Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Loading SQL results into grid headers

Posted on 2012-03-22
2
Medium Priority
?
419 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

927 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