0

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 by Narue: Added code tags

3
Contributors
3
Replies
8
Views
6 Years
Discussion Span
Last Post by adam_k
0

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 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.