473,395 Members | 1,516 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,395 software developers and data experts.

Populating my Combo Box from Access DB

17
I am having a problem with populating a combo box from a Access DB, I am calling a stored procedure that executes with one row of values. i want to populate those values into my combo box but right now the combo box will not populate. here is my code.


Expand|Select|Wrap|Line Numbers
  1. private void GetProductColors()
  2.         {
  3.             try
  4.             {
  5.                 if (oleDbConnection1.State != ConnectionState.Open)
  6.                 {
  7.                     oleDbConnection1.Open();
  8.                 }
  9.  
  10.                 //Initialize the location parameter to our GetColors ADO Command 
  11. Object
  12.                 oleDbCommandGetColors = new 
  13. OleDbCommand("SelectDistinctProductColors_sp", oleDbConnection1);
  14.                 oleDbCommandGetColors.CommandType = CommandType.StoredProcedure;
  15.                 oleDbCommandGetColors.Parameters.Clear();
  16.                 oleDbDataReader1 = 
  17. oleDbCommandGetColors.ExecuteReader(CommandBehavior.CloseConnection);
  18.  
  19.                 while (oleDbDataReader1.Read() == true)
  20.                 {
  21.                     cmbSelection.Items.Add(oleDbDataReader1.GetString(0));    
  22.                 }
Thanks
Oct 15 '07 #1
7 1504
Plater
7,872 Expert 4TB
If you only have ONE row, then you will only get one value from that loop.
Oct 15 '07 #2
blazted
17
I have 4 values in that row. I want to populate those values into the ComboBox. Right now it is not populating anything. I have tried adding those values to an array and then using the .add to add it but still nothing. Any ideas?
Oct 15 '07 #3
Plater
7,872 Expert 4TB
Try more like this:
Expand|Select|Wrap|Line Numbers
  1. if (oleDbDataReader1.Read())
  2. {
  3.    for(int i=0;i<oleDbDataReader1.FieldCount;i++)
  4.    {
  5.       cmbSelection.Items.Add(oleDbDataReader1.GetValue(i).ToString());
  6.    }
  7. }
  8.  
Oct 15 '07 #4
blazted
17
Try more like this:
Expand|Select|Wrap|Line Numbers
  1. if (oleDbDataReader1.Read())
  2. {
  3.    for(int i=0;i<oleDbDataReader1.FieldCount;i++)
  4.    {
  5.       cmbSelection.Items.Add(oleDbDataReader1.GetValue(i).ToString());
  6.    }
  7. }
  8.  
That worked great except it is only pulling down my second and 4th value from the stored procedure. Hm thats weird not sure why it would skip the 1st and third values.
Oct 15 '07 #5
Plater
7,872 Expert 4TB
Are you sure your stored procedure is returning what you think it's returning?

Have you dumped it into a dataset and looked at it?
Oct 15 '07 #6
blazted
17
I figured it out. It was an improper call. I used my original method. Not sure why your way would skip. Thanks for the help.
Oct 15 '07 #7
Plater
7,872 Expert 4TB
I think if you have multiple values stored in one column, or multiple columns with the same name, it would skip them.
Oct 15 '07 #8

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

Similar topics

2
by: Roy Padgett | last post by:
I have a combo box where users select the customer name and can either go to the customer's info or open a list of the customer's orders. The RowSource for the combo box was a simple pass-through...
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
4
by: Lumpierbritches | last post by:
Thank you once again for any and all assistance. I'm building an application that's getting quite bulky due to the number of forms, macros and procedures. I was wondering if there's a way to use 1...
13
by: melih.onvural | last post by:
Group, I'm having a tough time understanding some of the previous posts on this topic so I wanted to write what I've tried and hope that you can help me troubleshoot. I have a dropdown populated...
3
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the...
5
by: a Wellner | last post by:
I am trying to create a from that the user can select a street from a combo box (named street), then pick a second street from another combo box, containing only valid cross streets(named Cross). ...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
2
by: SHAWTY721 | last post by:
I have a form that contains two combo boxes that are related to each other. I need to find a way to populate my text box based on the criteria of the two combo boxes so the appropriate number...
0
pod
by: pod | last post by:
I am new to OOD and n-tier architecture but I want to start the right way. In Visual Studio, I have created a solution with three projects c/w reference to each other i.e. the Business Logic...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.