Click here to Skip to main content
15,941,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thank you for answer. Yes, it was my mistake but after changing field name to exact field name as "item Name". Now, it displays syntax error at line dr = cmd.ExecuteReader().
Please help me!!!
VB
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\panchani\Documents\Visual Studio 2005\Transport.mdb")
cmbName.Items.Clear()
cmd.Connection = cn
cmd.CommandText = "select Item Name from item_master"
cn.Open()
dr = cmd.ExecuteReader()
cmbName.Items.Clear()
While (dr.Read)
    cmbName.Items.Add(dr("Item Name"))
End While

dr.Close()
Posted
Updated 3-Jul-10 7:58am
v2

Please change the following line as follows.

SQL
cmd.CommandText = "select [Item Name] from item_master"



If the columnname of contains a space then it should be in square brackets i.e., [Item Name].

http://dotnetforbeginner.blogspot.com/[^]
 
Share this answer
 
v2
Comments
William Winner 1-Jul-10 12:28pm    
Reason for my vote of 5
yep...definitely the problem!
You need to declare the Data Reader as follows:

Dim cn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\panchani\Documents\Visual Studio 2005\Transport.mdb")
        Dim cmd As OleDbCommand = New OleDbCommand
        cmd.Connection = cn
        cmd.CommandText = "select [Item Name] from item_master"
        cn.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader()
        cmbName.Items.Clear()
        While (dr.Read)
            cmbName.Items.Add(dr("Item Name"))
        End While
        dr.Close()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900