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

Unusual problem when setting Combobox Display/Value members

36
Using this code, the display member of the combo box is displaying the text "System.Data.DataViewManagerListItemTypeDescriptor ". Huh???

The first block of code gets the data from the database, and works as far as I know. The second block of code sets the first value of the form, and does NOT work like I want it too. I commented out the line that sets the value member, because it gives an exception.

Expand|Select|Wrap|Line Numbers
  1. Public Function FillFromAccess(ByVal QueryString As String, ByVal FillTable As String)
  2.  
  3.         Dim OLEConnString As String
  4.         OLEConnString = "Provider=" & My.Settings.Connection_AccessProvider & ";" _
  5.             & "Data Source=" & My.Settings.Connection_Location & ";" ' _
  6.         '   & "Initial Catalog=Blah;" _
  7.         '   & "User Id=username;" _
  8.         '   & "Password='password';"
  9.  
  10.         Dim DBConn As New OleDbConnection(OLEConnString)
  11.  
  12.         Dim DBCommand As OleDbDataAdapter
  13.         Dim DataSetAccess As New DataSet
  14.  
  15.         ' For any data needed, pull it out of the database.
  16.         DBCommand = New OleDb.OleDbDataAdapter(QueryString, DBConn)
  17.         ' Once that's ready, use it to fill the dataset DSPageData:
  18.         DBCommand.Fill(DataSetAccess, FillTable)
  19.  
  20.         FillFromAccess = DataSetAccess
  21.  
  22.     End Function
Expand|Select|Wrap|Line Numbers
  1. Private Sub Add_action_items_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         'Load the job number into the job number combo box
  3.         Dim SQL As String
  4.         Dim DataSet_Jobs_Incomplete As New DataSet
  5.  
  6.         'Find the information from the database
  7.         SQL = "Select * From Jobs WHERE Completed <> True"
  8.         DataSet_Jobs_Incomplete = FillFromAccess(SQL, "Jobs_Incomplete")
  9.  
  10.         'Add the list of job numbers to the combo box
  11.         With CmbJobNum
  12.             .DataSource = DataSet_Jobs_Incomplete
  13.             '.ValueMember = "ID"
  14.             .DisplayMember = "Job_num"
  15.             .SelectedIndex = 0
  16.         End With
  17.  
  18.     End Sub
Dec 30 '08 #1
2 3510
Infog
36
I found the problem! I feel kind of silly now.

I didn't know how to reference which table in the dataset to use, and I had swapped the valuemember and displaymember.

The code below works to set a combobox to a list, pulled from a database.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Add_action_items_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         'Load the job number into the job number combo box
  3.         Dim SQL As String
  4.         Dim DataSet_Jobs_Incomplete As New DataSet
  5.  
  6.         'Find the information from the database
  7.         SQL = "Select * From Jobs WHERE Completed <> True"
  8.         DataSet_Jobs_Incomplete = FillFromAccess(SQL, "Jobs_Incomplete")
  9.  
  10.         'Add the list of job numbers to the combo box
  11.         With CmbJobNum
  12.             .DataSource = DataSet_Jobs_Incomplete.Tables(0)
  13.             .ValueMember = "ID"
  14.             .DisplayMember = "Job_num"
  15.             .SelectedIndex = 0
  16.         End With
  17.  
  18.     End Sub
Dec 30 '08 #2
Infog
36
More advice, for whoever may be researching this topic later -

If the correctly formed query you send to the database returns no records, VB.NET will give an exception. To stop that, catch the exception and send back the value Nothing. Now, it skips the exception, and you can test for Nothing in the sub that used the above function. That way, no controls are set to an index (ComboBox1.Index = 0) when their index doesn't actually exist.

I hope my past mistakes can be put to use by someone else...
Expand|Select|Wrap|Line Numbers
  1.         Try
  2.             DBCommand.Fill(DataSetAccess, FillTable)
  3.         Catch ex As Exception
  4.             FillFromAccess = Nothing
  5.             Exit Function
  6.         End Try
  7.  
Dec 31 '08 #3

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

Similar topics

0
by: CGuy | last post by:
URGENT HELP REQUIRED FROM GURUS Hi, I have a custom object that implements ICollection and IListSource. This object has also an enumerator defined for it which implements IEnumerator and...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
0
by: Susan Bricker | last post by:
The following error: "The current field must match the join key '?' in the table that seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the...
2
by: pmcguire | last post by:
OK. So I've been to http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp and learned a lot about what I might do with a datagrid. But I'm STILL not able to do what I want to do. I want to be able...
9
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
2
by: AMDRIT | last post by:
Hello Everyone, I would like to format the Display Members of a combobox's datasource. Is there a way to apply a format without subclassing the original datasource? For example, given a list of...
0
by: lv2compute | last post by:
I am having a problem with my datagridview. I have a small table that has two columns. The first column is bound to my dataset. The second column is a combobox. I add items to the combobox based on...
1
by: progressdll | last post by:
I'm trying to change the behaviour of setting the DataSource property of combobox. Here is the behaviour I now see. Setting the DataSource property of combobox to an ArrayList will visual...
5
by: jmDesktop | last post by:
I know this should be straight forward, but I have not gotten it yet. I have a combobox and a textbox. I want to display what is selected in the combobox in the textbox. I have: ...
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...
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.