Hi,
My Access database has one column named 'Term' and the Table name is 'ATG'. I require to populate my listbox with data in the 'Term' columns. I'm unable to do that using this code. Can anyone tell me what's wrong with this (it displays numbers from 1 to 10 and not the database data)

Imports System.Data.OleDb
Public Class Form1
  Dim dbConnection As OleDbConnection
  Dim dbCommand As OleDbCommand
  Dim strInsert As String
  Dim dbDataAdapter As OleDbDataAdapter
  Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source =atg.mdb"

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim dtATG As New DataTable
    dtATG.Columns.Add("Col1", GetType(Integer))
    For i As Integer = 1 To 10
      dtATG.Rows.Add(i)
    Next
    ListBox1.DisplayMember = "Col1"
    ListBox1.ValueMember = "Col1"
    ListBox1.DataSource = dtATG
  End Sub
End Class

Edited 5 Years Ago by Narue: Added code tags

dtATG.Rows.Add(i)

in the above line you need to add column values not the for loop counter.

Do you mean I need to add an SQL query? Can you explaina little more (P.S I'm just a beginner) Thanks a lot for the help.

This article has been dead for over six months. Start a new discussion instead.