Click here to Skip to main content
Sign Up to vote bad
good
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 - 1:32


1 solution

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  
Comments
CrugerBrent - 17 Jan '13 - 9:54
Thanks jenitshah..............................

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 330
2 Arun Vasu 253
3 Zoltán Zörgő 194
4 CPallini 173
0 Sergey Alexandrovich Kryukov 10,105
1 OriginalGriff 7,739
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 2,999


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid