473,721 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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 22677
danp129
323 Recognized Expert Contributor
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
nareshpulipati
5 New Member
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(Column s).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
nareshpulipati
5 New Member
Thanks for replying

When i debug these are the two errors i came across and also i used debug.print Category(Column s).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.OdbcConnec tion("Provider= Microsoft.Jet.O dbc.4.0;data source=" & kpi_database & "")

Sql = "SELECT [Comp_ItemNumber] FROM [Components] ORDER BY [Comp_ItemNumber] Asc"
Cmd = New Odbc.OdbcComman d(Sql, Con)
Jun 29 '07 #4
danp129
323 Recognized Expert Contributor
I haven't made a SQL app in vb.net only vb6. What DB are you connecting to?
Jun 29 '07 #5
nareshpulipati
5 New Member
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
nareshpulipati
5 New Member
IAm connecting to ODBC
Oracle data base of the company
Jun 29 '07 #7
danp129
323 Recognized Expert Contributor
One of these strings for Oracle should work.

http://www.carlprothma n.net/Default.aspx?ta bid=90
Jun 29 '07 #8

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

Similar topics

0
6435
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 be modified: if(e.CommandName =="Print") { string parsedreceipt = null; parsedreceipt = DecodeReceipt (e.Item.Cells.Text); Session = parsedreceipt;
1
1362
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 box(dropdown list). How would I do this in C#? It seems like it should be real easy but I can't make it work. Thanks in advance
4
3003
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 added to the data grid. My current code is coming up with errors, dt and drv are unknown in the else part of the if statement. if (this.dgPrivileges.DataSource == null) {
4
301
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
2137
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 Sales 1 Monthly Terms 1 Sales 2 Annual Terms
1
8737
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 all of the report from the reporting server (sql server reporting services 2000). to do this i have done:
1
6001
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 "cmSelectAllCompanyNames" table, and put all the company names it finds into the "cbFilterCompanyName" combo box. Now the confusing aspect is this: It works!!!
0
3840
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 for the first time versus when the form is posted (sent to the server), which allows you to program accordingly. · What are user controls and custom controls? Custom controls: A control authored by a user or a third-party software vendor that...
4
3526
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 is what I have for form fields: Carton # <auto number> Item Title <txt> Item Accquisition Date <txt (date)> Is item consigned <yes/no>
5
4006
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 Fields Names: countrycode, make
0
8847
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9225
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9137
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9071
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6675
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5991
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4758
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3197
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2135
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.