Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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 at 17-Jan-13 9:54am
   
Thanks jenitshah..............................

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2014
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