3
Contributors
2
Replies
23
Views
3 Years
Discussion Span
Last Post by arun1123
0

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

Edited by Reverend Jim

0

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"

Vb.Net

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

        setConn()
        Populate_DataSet()
        FillListbox()

    End Sub

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

        lstSample.Items.Clear()
        For Each row In ds.Tables("BookName").Rows
            lstSample.Items.Add(ds.Tables("BookName").Rows(iRowCnt).Item(1))
            iRowCnt = iRowCnt + 1
        Next
    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)
        objConn.Open()

        Return True
    End Function
End Class
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.