Results 1 to 3 of 3

Thread: mySQL and Display in Listbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    mySQL and Display in Listbox

    I'm trying! I have my book, but it won't show mySQL examples.

    I think I've sucessfully got vb to reconize the database. I can go to the data manager and view the tables and whatnot.

    I just need to know where the right place to look at to find out what code I need to use to grab information from the table. I'm not seeing any smart drop down vars so I'm real confused.

    Just need to grab the info from the database and put it into a listbox

    Thanks for the help.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: mySQL and Display in Listbox

    I have not used mySQL yet but I think you need to create recordsets in order to grab data from your database.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: mySQL and Display in Listbox

    Alright This works perfectly!
    VB Code:
    1. Private Sub Form_Load()
    2. '==============================
    3. Dim rs As New ADODB.Recordset
    4. Dim cn As New ADODB.Connection
    5. Dim ITM As ListItem
    6.  
    7.     cn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;" & _
    8.                           "DATABASE=Pizazzy;USER=;PASSWORD=;OPTION=3;"
    9.     cn.Open
    10.         sql = "SELECT * FROM Messages"
    11.     rs.Open sql, cn, adOpenForwardOnly, adLockOptimistic
    12.    
    13.     ListView1.View = lvwReport
    14.     ListView1.ColumnHeaders.Add 1, , "From"
    15.     ListView1.ColumnHeaders.Add 2, , "Message"
    16.         With rs
    17.         Do Until rs.EOF = True
    18.             Set ITM = ListView1.ListItems.Add(1, "", Trim(!From))
    19.             ITM.SubItems(1) = IIf(IsNull(!Msg), "", Trim(!Msg))
    20.             .MoveNext
    21.         Loop
    22.     End With
    23.  
    24. End Sub

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