Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2013
    Posts
    16

    Unanswered: Help Required For Combo box Autopopulating 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

  2. #2
    Join Date
    Jun 2015
    Posts
    2
    this worked fine for me :

    Private Function GetConnectionString() As String
    Return "Data Source=(LocalDB)\v11.0;AttachDbFilename=" & Get_path() & "\TesterStatus\tsdb.mdf;Trusted_Connection=True;Ap plicationIntent=ReadWrite;Integrated Security=True;MultiSubnetFailover=Yes"
    End Function

    Private Sub fill_combostatus()
    'Dim stat As String
    Combostatus.Items.Clear()
    'connect to db
    Dim connectionString As String = GetConnectionString()
    Dim conn As New SqlConnection(connectionString)
    conn.Open()

    'fill hwvariant combobox
    Dim strtester As String
    strtester = "SELECT * FROM dbo.tester"
    Dim commtester As New SqlCommand(strtester, conn)
    Dim readertester As SqlDataReader = commtester.ExecuteReader()
    While (readertester.Read())
    Combostatus.Items.Add(Trim(readertester("Tester")) )
    End While
    commtester.Dispose()
    readertester.Close()
    conn.Close()
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •