Correction Req For Combo box code
Hello
I m using VB 2008 and Access 2007.
Access File Name : a
Access Table Name: emp
data source=E:\a
one combobox : ComboBox1
My Access have 4 columns "EmpID",EmpName","Disgination",GrossSalary",.
I want that the combo box pick the data of EmpName automatically . I have try three type of codes but every code shows error " could not find the file E:\a.mdb. I check the path several time and confirm the path.some time the code execute but the combo box show nothing.
I am very disturb due to this problem.Because of this one of my project has been stopped.I request to any experience person to help me and given me a simple and clean code according to my needs.And also let me clear that why i m facing this problems.The code i m used are given below.For better . Thanks
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=E:\a.mdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT EmpName FROM emp", con)
con.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "emp")
'Idea 1
ComboBox1.DataSource = myDataSet.Tables("emp").DefaultView
ComboBox1.ValueMember = "EmpName"
ComboBox1.DisplayMember = "EmpName"
'Idea 2
'For Each dRow As DataRow In myDataSet.Tables("emp").Rows
'ComboBox1.Items.Add(dRow.Item("EmpID"))
'Next
'Idea 3
'Dim sdr As OleDbDataReader = cmd.ExecuteReader
'While sdr.Read()
'ComboBox1.Items.Add(sdr.Item("emp").ToString)
'End While
con.Close()
con = Nothing
End Sub