Click here to Skip to main content
14,977,259 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello. I am working on a project using SQlite for the first time. I have been able to load all tables to display in a combobox. Now i need to be able to display the details of any table you selected from the combobox to be displayed in a Listview.
I'll indeed be very grateful thank u.

What I have tried:

Dim conn As New SQLite.SQLiteConnection
Dim cmd As SQLiteCommand
Dim da As SQLite.SQLiteDataAdapter
Dim ds As SQLiteDataReader
Dim itemcoll(100) As String

Me.ListView1.View = View.Details
Me.ListView1.GridLines = True
conn = New SQLiteConnection(db)
Dim strQ As String = String.Empty
strQ = "SELECT * FROM " & ComboBox1.Text & """"
cmd = New SQLiteCommand(strQ, conn)
da = New SQLite.SQLiteDataAdapter(cmd)
Posted
Updated 9-Mar-21 7:29am

   
Try this:

VB
Dim conn As New SQLiteConnection("Data Source=myDatabase.sql3;Version=3;")
        conn.Open()
        dim SQL as string = "SELECT * from lang;"
        Dim da As New SQLiteDataAdapter(Sql, conn)
        Dim ds As New DataSet
        da.Fill(ds, "lang")
        'Close the connection
        conn.Close()
        'ListView1
        With ListView1
            .View = View.Details
            .HeaderStyle = ColumnHeaderStyle.Nonclickable ' set to whatever you need
            .Columns.Clear() ' make sure columnscollection is empty
            ' Add 3 columns
            .Columns.Add(ds.Tables(0).Columns(0).ColumnName)
            .Columns.Add(ds.Tables(0).Columns(1).ColumnName)
            .Columns.Add(ds.Tables(0).Columns(2).ColumnName)

        End With
        For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
            ListView1.Items.Add(New ListViewItem({ds.Tables(0).Rows(i).Item(0).ToString(), ds.Tables(0).Rows(i).Item(1).ToString(), ds.Tables(0).Rows(i).Item(2).ToString()}))
        Next


This shows the whole process.
* Open the database
* Create the DataAdaptor(da) using the connection and SQL statement
* Create the dataset (ds)
* Fill the DataAdaptor with the contents of the lang table
* Add Columns to the Listview
* Add the contents of fields to the ListView
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900