guys can you please help me in displaying columns from my ms access table to a listview in vb.net..

i use oledb in connecting to ms access..

Recommended Answers

All 2 Replies

try this:

Imports System.Data
Imports System.Data.OleDb

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim con As New OleDbConnection("Connection string")
    Dim cmd As New OleDbCommand
    Dim da As New OleDbDataAdapter

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        con.Open()
        cmd = New OleDbCommand("select * from Table1", con)
        Dim dt As New DataTable
        da.SelectCommand = cmd
        da.Fill(dt)
        ListView1.DataSource = dt      
        ListView1.DataBind()

    End Sub

I'm not an expert but I'm pretty sure there is no DataSource property for a ListView at least not in VB2008 and framwork 3.5. I think you're going to have to loop through the datatable and add the items to the listview that way. I believe the DataGridView would work for what you want and it has a DataSource property that's very easy to implement.

Ken

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.