Results 1 to 3 of 3

Thread: Two Database Fields in One Listbox

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    53

    Two Database Fields in One Listbox

    I'm stuck on this one, so I'm on my knees begging for help.

    I have two fields in a database, LastName and FirstName. I want to fill a listbox so that each row in the database appears like this:

    -------------------------------
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    ------------------------------

    I can get it to work fine with one or the other as the text field, but how do you show two text fields?

    HWOODKY

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Two Database Fields in One Listbox

    Originally posted by HollywoodKY
    I'm stuck on this one, so I'm on my knees begging for help.

    I have two fields in a database, LastName and FirstName. I want to fill a listbox so that each row in the database appears like this:

    -------------------------------
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    | LastName, FirstName |
    ------------------------------

    I can get it to work fine with one or the other as the text field, but how do you show two text fields?

    HWOODKY
    like this..if not sorry
    VB Code:
    1. Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         cn.Open()
    3.         cm.Connection = cn
    4.         cm.CommandType = CommandType.StoredProcedure
    5.         getd()
    6.     End Sub
    7.     Sub getd()
    8.         Try
    9.             With cm
    10.                 .Parameters.Clear()
    11.                 .CommandText = "retrievecustomer"
    12.                 Dim r As SqlDataReader = .ExecuteReader
    13.                 While r.Read
    14.                     Dim s As String = r.GetValue(0)
    15.                     Dim x As String = " , " & r.GetValue(1)
    16.                     Dim f As String = s & x
    17.                     ListBox1.Items.Add(f)
    18.                 End While
    19.                 r.Close()
    20.             End With
    21.         Catch ex As Exception
    22.             MsgBox(ex.Message)
    23.         End Try
    24.     End Sub

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    I find the best way is to load the database fields into an arraylist. You can then easily put them in what order you wish in the listbox.
    Last edited by taxes; Jun 17th, 2004 at 06:16 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width