473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VB.NET: How to populate combo box with database item

Hi all,
I am new to VB .net.
Iam trying to populate the database item into combo box.
Database Type:SQL(ODBC)
My code retuns no value in combo box
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  3.         Dim Cmd As Odbc.OdbcCommand
  4.         Dim Con As Odbc.OdbcConnection
  5.         Dim Sql As String = Nothing
  6.         Dim Reader As Odbc.OdbcDataReader
  7.         Dim ComboRow As Integer = -1
  8.         Dim Columns As Integer = 0
  9.         Dim Category As String = Nothing
  10.         Dim Cmbbox As ComboBox
  11.  
  12.         CmbboxMan.Items.Clear()
  13.  
  14.         Con = New Odbc.OdbcConnection("Provider=Microsoft.Jet.Odbc.4.0;data source=" & Database & "")
  15.  
  16.         Sql = "SELECT [Comp_ItemNumber] FROM [Components] ORDER BY [Comp_ItemNumber] Asc"
  17.         Cmd = New Odbc.OdbcCommand(Sql, Con)
  18.         Con.Open()
  19.  
  20.         Reader = Cmd.ExecuteReader()
  21.         While Reader.Read()
  22.             For Columns = 0 To Reader.FieldCount - 1
  23.                 Category = Reader.Item(Columns) 'READ COLUMN FROM DATABASE
  24.             Next
  25.             Cmbbox.Items.Add(Category)
  26.             ComboRow += 1
  27.         End While
  28.         Con.Close()
  29.     End Sub
  30. End Class
Plz reply ASAP
Jun 28 '07 #1
7 22638
danp129
323 Expert 256MB
Is category blank?
Expand|Select|Wrap|Line Numbers
  1. For Columns = 0 To Reader.FieldCount - 1
  2.     Category = Reader.Item(Columns) 'READ COLUMN FROM DATABASE
  3.     debug.print Category
  4. Next
use [CODE=VB]code here[/CODE] tags please
Jun 28 '07 #2
Is category blank?
Expand|Select|Wrap|Line Numbers
  1. For Columns = 0 To Reader.FieldCount - 1
  2.     Category = Reader.Item(Columns) 'READ COLUMN FROM DATABASE
  3.     debug.print Category
  4. Next
use
Expand|Select|Wrap|Line Numbers
  1. code here
tags please

Thanks for replying

When i debug these are the two errors i came across and also i used debug.print Category(Columns).Because its showing declaration error when i use debug.print Category

Error 1 Name 'CmbBoxMan' is not declared. C:\Documents and Settings\naresh\Desktop\VB COMBO BOX WITH SQL DATA SOURCE\VB COMBO BOX WITH SQL DATA SOURCE\Form1.vb 13 9 VB COMBO BOX WITH SQL DATA SOURCE

Error 2 Name 'Database' is not declared. C:\Documents and Settings\naresh\Desktop\VB COMBO BOX WITH SQL DATA SOURCE\VB COMBO BOX WITH SQL DATA SOURCE\Form1.vb 15 88 VB COMBO BOX WITH SQL DATA SOURCE


Please help me
Jun 29 '07 #3
Thanks for replying

When i debug these are the two errors i came across and also i used debug.print Category(Columns).Because its showing declaration error when i use debug.print Category

Error 1 Name 'CmbBoxMan' is not declared. C:\Documents and Settings\naresh\Desktop\VB COMBO BOX WITH SQL DATA SOURCE\VB COMBO BOX WITH SQL DATA SOURCE\Form1.vb 13 9 VB COMBO BOX WITH SQL DATA SOURCE

Error 2 Name 'Database' is not declared. C:\Documents and Settings\naresh\Desktop\VB COMBO BOX WITH SQL DATA SOURCE\VB COMBO BOX WITH SQL DATA SOURCE\Form1.vb 15 88 VB COMBO BOX WITH SQL DATA SOURCE


Please help me



IS THIS CODE CORRECT TO CONNECT TO SQL DATABASE


Con = New Odbc.OdbcConnection("Provider=Microsoft.Jet.Odbc.4 .0;data source=" & kpi_database & "")

Sql = "SELECT [Comp_ItemNumber] FROM [Components] ORDER BY [Comp_ItemNumber] Asc"
Cmd = New Odbc.OdbcCommand(Sql, Con)
Jun 29 '07 #4
danp129
323 Expert 256MB
I haven't made a SQL app in vb.net only vb6. What DB are you connecting to?
Jun 29 '07 #5
I haven't made a SQL app in vb.net only vb6. What DB are you connecting to?

IAm connecting to ODBC
Jun 29 '07 #6
IAm connecting to ODBC
Oracle data base of the company
Jun 29 '07 #7
danp129
323 Expert 256MB
One of these strings for Oracle should work.

http://www.carlprothman.net/Default.aspx?tabid=90
Jun 29 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
1
by: Lance | last post by:
I am trying to select the item in the dropdown list the matches a value pulled from the database and set this matching item's selected property to true so that it is the selected item in the combo...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
4
by: Ziv Riezman | last post by:
Hi All I Have a datagrid on asp.net. i need to add a combo box column that chages it's data according to a spefiiec row in a datagrid. Please help me ?? Thnaks Ziv Riezman
0
by: ROO | last post by:
Hi Everyone, I have a database table that have 4 field( C1, C2, M1, M2) on my form i have two combo box ComboC and ComboM C1 C2 M1 M2 1 ...
1
by: roadie.girl | last post by:
Hey guys - I'm really new to this .NET programming so please bear with me ... (vb.NET) I'm trying to fill in the list contents of a combo box on the open event of a form. this list will list...
1
by: freekedoutfish | last post by:
Hi. New member here Im sat at work, pounding my head off the desk because this tiny bit of simple code refuses to work. The sub is intended to pull data from the "companyname" column in the...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
4
by: scolivas | last post by:
I think this is a me thing. but can't remember how to do it. I have a form that I am using and would like for a txt box to automatically populate based on what is selected in a combo box. here...
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.