Click here to Skip to main content
12,065,354 members (43,398 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
Hi there,
I'm new to vb and I need to know a thing. I've made a simple form by using vb.net. There I entered a combobox and I connected it to a access database. But when I'm running the program, when I click the drop down mark I won't get the details from the connected database. Can somebody tell me what's the wrong with my code?
here is the code
[code]
Imports System.Data
Public Class Form1
Dim inc As Integer
Dim MaxRows As Integer

Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "PROVIDER = Microsoft.ace.oledb.12.0;data source = ItemList.accdb"
con.Open()

sql = "SELECT * FROM Item_List"
da = New OleDb.OleDbDataAdapter(sql, con)

da.Fill(ds, "ItemList")
con.Close()

MaxRows = ds.Tables("ItemList").Rows.Count
inc = -1

End Sub


End Class
[/code]

My vb version is vb 2005 express edition.
Posted 17-Jan-13 2:32am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this :

Imports System.Data.OleDb
Public Class homemain
    Dim cnn As New OleDbConnection(<connection string="">)
    Dim cmd As New OleDbCommand
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)handles Button1.Click
        
     cnn.Open()
     cmd.Connection=cnn
     cmd.CommandText="select empname from employee"
     
     Dim dr As OleDbDataReader=cmd.ExecuteReader
     
     While dr.Read
         cmbempname.items.add(dr.item(0))
     End While
     dr.close()
End Sub
End Class
Hope, This will help you.
  Permalink  
v2
Comments
CrugerBrent 17-Jan-13 9:54am
   
Thanks jenitshah..............................
Ramya Chandran 11-Dec-15 10:57am
   
sir,

I am doing translator program how to write the program for english to tamil translation coding. how will you start the procedure for that program.
I am using front end vb.net and back end ms access and using combo box populate the data from database. give some suggestion

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160204.4 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100