0

I am trying to populate combobox from access database but not geting populated

only message 1 is displayed message 2 ,3 & 4 are not displayed, nither any eror is shown

------------------------------------
Imports System.Data.OleDb

Public Class FrmPlPostCodeNl
Public acsconn As New OleDb.OleDbConnection
Public acsdr As OleDbDataReader
Public strSql As String

Private Sub FrmPlPostCodeNl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(1)
acsconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;data source = D:\Shabeeb\SSS.accdb"
acsconn.Open() '"
MsgBox(2)
strSql = "Select * from NLCODES"
Dim acscmd As New OleDb.OleDbCommand
acscmd.CommandText = strSql
acscmd.Connection = acsconn
acsdr = acscmd.ExecuteReader
While (acsdr.Read())
ComboBox1.Items.Add(acsdr("ID"))
End While
acscmd.Dispose()
acsdr.Close()
MsgBox(4)

End Sub

2
Contributors
2
Replies
24
Views
4 Years
Discussion Span
Last Post by PM312
0

Try using the GetValue method and the ordinal position of the field you want from the query.
This would be "Select Field From Table" you are requesting 1 field so that's position 0

 ComboBox1.Items.Add(CStr(DataReader.GetValue(0)))
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.