簡體   English   中英

在DataGridView VB.net中顯示SQLite數據

[英]Displaying SQLite Data In DataGridView VB.net

我正在使用sqlite數據庫並使用vb.net我試圖在datagridview中打印一些行。 我使用以下代碼:

Public Sub LoadUsername()
    Dim ConnectionString As String = "Data Source=info.sqlite"
    Dim nSQL As String = "SELECT Name From employee"
    Dim dt As DataTable = Nothing
    Dim ds As New DataSet

    Try
        Using con As New SQLiteConnection(ConnectionString)
            Using cmd As New SQLiteCommand(nSQL, con)
                con.Open()
                Using da As New SQLiteDataAdapter(cmd)

                    Console.WriteLine(da)
                    da.Fill(ds)
                    dt = ds.Tables(0)
                End Using
            End Using
        End Using

        ListBox1.ValueMember = "Name"
        ListBox1.DisplayMember = "FullName"
        ListBox1.DataSource = dt

    Catch ex As Exception
        MsgBox(ex.Message)

    End Try

End Sub

但是當我執行或編譯這個程序時,它會在名稱應該是的字段中顯示System.Data.DataRowView 請檢查圖像。 謝謝!

在此輸入圖像描述

您的數據表中沒有FullName列,但您正在嘗試將顯示綁定到該列。 DisplayMember更改為Name,因為它應該正常工作。

System.Data.DataRow只是默認的ToString實現,因為它無法找到您的fullname屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM