Canadian Computer Consulting

VB.NET ComboBox & SQL

Home
About Us
Contact Us
Links
Data Recovery
Computers
Virus Repair
Spyware
File Sharing
Web Hosting
Fun Stuff
Misc. Tips
Make A Payment
Annoying Phone Numbers

The Problem

Using VB.NET, I'm trying to databind a ComboBox to a DataView that I populated using SQL.  No matter what I do, it returns the right number of fields in the ComboBox, but every single one just says "System.Data.DataRowView".  I've tried using the dataset directly instead of the dataview with no change in result.

My code looks something like this:

SQLcommand = "select id, column1 from mytable"

cbo.DisplayMember = "Column1"
cbo.ValueMember = "ID"
cbo.DataSource = dv

My program looks like this:

The number of lines is correct, the table returns three rows.  The problem is I can't get it to display the data in the rows.

The Solution

A BIG thank you to "Liebrand" on Experts-Exchange.com for this answer.

The "DisplayMember" and "ValueMember" values are CASE SENSITIVE.  Argh.  Either change the SQLcommand to look like this:

SQLcommand = "select ID, Column1 from mytable"

or change the code to look like this:

cbo.DisplayMember = "column1"
cbo.ValueMember = "id"
cbo.DataSource = dv


Copyright © 2008 Canadian Computer Consulting
(updated March 22, 2008)

Vancouver: 604-249-4486   Victoria: 250-412-1593    Edmonton: 780-701-7167
Email info@computerconsulting.ca