Solved

Loading SQL results into grid headers

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now