Menu

DataTreeListview and SQLite database

Help
CFrank
2015-02-11
2015-02-16
  • CFrank

    CFrank - 2015-02-11

    Hello,

    I do have a SQLite database and want to use a DataTreeListview to show the
    output of two joined tables.
    The SQL query works in the SQLite Manager (Firefox Addon) and returns the expected
    rows. A Debug.Print of the columns and rows of the resulting dataset works also.
    So I guess I do something wrong by binding the dataset to the DataTreeListview, maybe
    someone can enlight me waht I am doing wrong.

    Here is waht I've done so far

    Imports BrightIdeasSoftware.TreeListView
    Imports System.Data
    Imports System.Data.SQLite
    
    Public Class Form1
    
        Dim ObjConnection As SQLiteConnection
    
        Private Sub btnReload_Click(sender As System.Object, e As System.EventArgs) Handles btnReload.Click
            Dim ObjCommand As SQLiteCommand = New SQLiteCommand("SELECT Categories.Category_ID, Categories.Category, Categories.Parent_ID, Code.Code, Code.Example FROM Categories LEFT JOIN Code USING(Category_ID)", ObjConnection)
    
            ObjCommand.CommandType = CommandType.Text
            Dim ObjDataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(ObjCommand)
    
            Dim _dataset As DataSet = New DataSet()
            ObjDataAdapter.Fill(_dataset)
    
            'Dim _datatable As DataTable = New DataTable("Table")
            'With _datatable
            '    .Columns.Add("Category_ID", GetType(Integer))
            '    .Columns.Add("Category", GetType(String))
            '    .Columns.Add("Parent_ID", GetType(Integer))
            '    .Columns.Add("Code", GetType(String))
            '    .Columns.Add("Example", GetType(String))
    
            '    .Rows.Add(1, "Database", 0, "Database_Code", "Database_Example")
            '    .Rows.Add(2, "Network", 0, "Network_Code", "Network_Example")
            '    .Rows.Add(3, "Protocols", 0, "Protocols_Code", "Protocols_Example")
            '    .Rows.Add(4, "Filesystem", 0, "Filesystem_Code", "Filesystem_Example")
            '    .Rows.Add(5, "Graphics", 0, "Graphics_Code", "Graphics_Example")
            '    .Rows.Add(6, "Applications", 0, "Applications_Code", "Applications_Example")
            '    .Rows.Add(7, "Controls", 0, "Controls_Code", "Controls_Example")
            '    .Rows.Add(8, "WindowsAPI", 0, "WindowsAPI_Code", "WindowsAPI_Example")
            '    .Rows.Add(9, "Miscellaneous", 0, "Miscellaneous_Code", "Miscellaneous_Example")
            '    .Rows.Add(10, "LanguageSpecific", 0, "LanguageSpecific_Code", "LanguageSpecific_Example")
            '    .Rows.Add(11, "Threading", 0, "Threading_Code", "Threading_Example")
            '    .Rows.Add(12, "Filehandling", 4, "Filehandling_Code", "Filehandling_Example")
            'End With
            '_dataset.Tables.Add(_datatable)
    
            With Me.DataTreeListView1
                .ShowKeyColumns = True
                .KeyAspectName = "Category_ID"
                .ParentKeyAspectName = "Parent_ID"
                .RootKeyValue = 0
                .DataSource = _dataset
                .DataMember = "Table"
                '.BuildList(True)
                '.RebuildAll(True)
            End With
    
            Debug.Print(String.Format("{0} {1} {2} {3} {4}", _dataset.Tables("Table").Columns(0).Caption, _dataset.Tables("Table").Columns(1).Caption, _dataset.Tables("Table").Columns(2).Caption, _dataset.Tables("Table").Columns(3).Caption, _dataset.Tables("Table").Columns(4).Caption))
    
            For Each row In _dataset.Tables("Table").Rows
                Debug.Print(String.Format("{0} {1} {2} {3} {4}", row.Item(0), row.Item(1), row.Item(2), row.Item(3), row.Item(4)))
            Next
    
        End Sub
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            ObjConnection = New SQLiteConnection("Data Source=Sourcebook.sqlite;")
        End Sub
    End Class
    
    <Debug.print output>
    SQLite warning (284): automatic index on Code(Category_ID)
    Category_ID Category Parent_ID Code Example
    1 Database 0 Database_Code Database_Example
    2 Network 0 Network_Code Network_Example
    3 Protocols 0 Protocols_Code Protocols_Example
    4 Filesystem 0 Filesystem_Code Filesystem_Example
    5 Graphics 0 Graphics_Code Graphics_Example
    6 Applications 0 Applications_Code Applications_Example
    7 Controls 0 Controls_Code Controls_Example
    8 WindowsAPI 0 WindowsAPI_Code WindowsAPI_Example
    9 Miscellaneous 0 Miscellaneous_Code Miscellaneous_Example
    10 LanguageSpecific 0 LanguageSpecific_Code LanguageSpecific_Example
    11 Threading 0 Threading_Code Threading_Example
    12 Filehandling 4 Filehandling_Code Filehandling_Example
    </Debug.print output>
    

    If I'm generating the dataset and datatable, as I did in the commented part, the DataTreeListview shows the expected rows but the debug output looks the same.

    Any ideas?

    Thx
    Claudia

     
  • CFrank

    CFrank - 2015-02-16

    OK - Problem found and solved.
    SQLite.Net defines INTEGER as INT64.
    As I'm developing on a 32bit OS I guess ObjectListview treats
    INTEGER as INT32 and therefore I did have the problem.
    (Still confused that I didn't get an conversion error)
    After converting the INTEGER columns to int32 everything is shown as expected.

    Thx
    Claudia

     

Log in to post a comment.