Results 1 to 5 of 5

Thread: [RESOLVED] Populate listview with a MySQL Database

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Resolved [RESOLVED] Populate listview with a MySQL Database

    Ok, so Ive been searching around but havent been able to find a relevant answer.

    I have a local MySQL server which has a database. Now, I want to populate a listview with all entries (Rows) in that database. How would I go about?

    EDIT:

    Ive manage to write entries to the database, and im using the following code. I just need to know how to populate a listview..

    Code:
    con = New MySqlConnection()
            Dim command As New MySqlCommand
            Dim conString As String
            Dim SQL As String
            Dim to_name As String
            Dim from_name As String
            Dim emne_name As String
            Dim cat_name As String
            Dim message As String
            Dim operator_name As String
    
            conString = "server=localhost;" _
                         & "user id=root;" _
                         & "password=123test;" _
                         & "database=radiologg"
    
            from_name = ComboBox_fra.Text
            to_name = ComboBox_Til.Text
            emne_name = TextBox_emne.Text
            cat_name = ComboBox_emne.Text
            message = RTextBox_msg.Text
            operator_name = label_operator_value.Text
    
            SQL = "INSERT INTO samband_logg(time, fra, til, topic, cat, message, operator) VALUES(?time, ?from, ?to, ?topic, ?cat, ?message, ?operator)"
            command.Parameters.AddWithValue("?time", from_name)
            command.Parameters.AddWithValue("?from", from_name)
            command.Parameters.AddWithValue("?to", to_name)
            command.Parameters.AddWithValue("?topic", emne_name)
            command.Parameters.AddWithValue("?cat", cat_name)
            command.Parameters.AddWithValue("?message", message)
            command.Parameters.AddWithValue("?operator", operator_name)
    
            con.ConnectionString = conString
            command.Connection = con
            command.CommandText = SQL
            Try
                con.Open()
    
                command.ExecuteNonQuery()
            Catch ex As MySqlException
                MessageBox.Show("Error connecting to database: " & ex.Message)
            Finally
                If con.State <> ConnectionState.Closed Then
                    con.Close()
                    MessageBox.Show("Rapport lagt in")
                    Me.Close()
                End If
    
            End Try
    Last edited by Untouchab1e; Aug 24th, 2009 at 05:26 PM. Reason: Solved

Tags for this Thread

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