Bishnu Dev Bishnu Dev - 3 months ago 65
Vb.net Question

Displaying SQLite Data In DataGridView VB.net

I am using sqlite database and using vb.net i am trying to print some rows in datagridview. I use the following code:

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


but when i execute or compile this program, it shows me System.Data.DataRowView in the field where name should be. please check the image. Thanks!

enter image description here

Answer

There is no FullName column in your datatable yet that's what you're trying to bind the display to. Change the DisplayMember to Name as it should work correctly.

System.Data.DataRow is just the default ToString implementation as it cant find your fullname property.

Comments