I have a database with items which I want to populate to a listbox.
The first image shows how its right now, and the second shows how I want the final result to look like.


Recommended Answers

All 2 Replies

There are examples here for both OleDB and SQLDB. Just modify the code to add the items to a listbox instead of a listview.

The first one is an image of a gridview and if that is how you want it to be then check this article.

An example of a "CheckListBox"


Option Explicit On

Imports System.Data.SqlClient

Public Class Form1

    Dim SqlAdapter As System.Data.SqlClient.SqlDataAdapter
    Dim ds As New DataSet
    Dim objConn As SqlConnection

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub

    Private Sub FillListbox()
        Dim row As DataRow
        Dim iRowCnt As Integer = 0

        For Each row In ds.Tables("BookName").Rows
            iRowCnt = iRowCnt + 1
    End Sub

    Private Sub Populate_DataSet()
        Dim sClarity As String = "SELECT *FROM dbo.BOOKS"

        SqlAdapter = New System.Data.SqlClient.SqlDataAdapter(sClarity, objConn)
        SqlAdapter.Fill(ds, "BookName")
    End Sub

    Private Function setConn() As Boolean
        Dim gs_ConnString = "Data Source=CLUB;Persist Security Info=False;" & _
                    "Initial Catalog=BookStore;User Id=sa;Password=123;Connect Timeout=500;"

        objConn = New SqlConnection(gs_ConnString)

        Return True
    End Function
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.