Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Given a Combo box [Cb] and Dataset [ds].

Dataset [ds] is a set of distinct values from a column in my SQL Table, I want to display this list in the combo box. Mimicking my methods in VB6 I did the following:

Cb.DataSource = ds;

 

However instead of displaying the list of Customers [which it does in VB6] I get the following as the first and only value of the combo box:

System.Data.DataViewManagerListItemTypeDescriptor

 

Anyclues?

  • *Experts*
Posted

You have to also set the DisplayMember property. If you set the DataSource to a DataSet, the DisplayMember should be "TableName.ColumnName". If you bind DataSource to a DataTable, then the DisplayMember can be the column name.

 

comboBox1.DataSource = myDataSet;
comboBox1.DisplayMember = "LookupTable.Val";

comboBox2.DataSource = myDataSet.Tables["LookupTable"];
comboBox1.DisplayMember = "Val";

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Doesn't give an error compiling but the result is the same.

Let me elaborate more, might help.

 

I have a Table called [store], it houses 5 Columns [storeName, StoreType, Bool1, Bool2, StoreID]. Each StoreName has 2 StoreTypes so I pass the following SQL Query and fill my Dataset with the results: "select distinct [storeName] from [store]"

 

Now I know my Dataset is ok because I can set it as Datasource of a Datagrid and the proper distinct StoreNames appear perfectly.

 

Using your approach I did the following:

Cb.DataSource = ds;

Cb.DisplayMember = "Store.StoreName"';

 

And sadly I get the exact same result, my ComboBox is filled with 1 value and it is "System.Data.DataViewManagerListItemTypeDescriptor" again.

 

But I think we are on the right track, in VB6 I had to do something similar to get it to work.

  • 4 weeks later...
Posted

Hey Shaitan00 & others,

 

Did you figure that problem out? :) If so, how did you fix it? I recently started a similar project and am getting the exact error.

Any help would be greatly appreciated.

 

Cheers,

 

digitalk

Posted

Dim dt As New DataTable("Table")

.

. 'Fill datatable here...know that the table fills with a column named "ColumnName"

.

dv = New DataView(dt)

Me.cmbSegCode.DataSource = dv

Me.cmbSegCode.DisplayMember = "ColumnName"

 

Works for me!

Posted

problems

 

Hello,

 

I still seem to be having problems so I thought it would be helpful to see the code.

 

*test is my dataset *

*conn is SQL connection string*

 

Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("", Conn1)

 

Conn1 = New OleDb.OleDbConnection(conn)

OleDbDataAdapter.Fill(test)

 

Dim custTables As DataTable = test.Tables.Add("CustTable")

 

Dim custDV As DataView = New DataView(test.Tables("CustTable"))

 

Dim custDV2 As DataView = test.Tables("CustTable").DefaultView

 

Me.ComboBox2.DataSource = custDV2

Me.ComboBox2.DisplayMember = "SITE"

 

The program runs through this after pressing a button but nothing is displayed. When it is pressed again, it crashes out with this error:

 

----------------------------------------

An unhandled exception of type 'System.Data.DuplicateNameException' occurred in system.data.dll

 

Additional information: A DataTable named 'CustTable' already belongs to this DataSet.

----------------------------------------

 

Any suggestions? Thoughts?

 

Thanks in advance. :)

 

Ciau...

 

Karl

  • *Experts*
Posted

The line:

Dim custTables As DataTable = test.Tables.Add("CustTable")

 

is adding a table with the name "CustTable" to your dataset. If you run through this code twice, you'll be trying to create a table that already exists in the dataset. That's your error.

 

What do you expect the following line to do:

OleDbDataAdapter.Fill(test)

 

You need to create an instance of OleDbDataAdapter, set it's sql to something like "SELECT * FROM Table1" and THEN call Fill.

 

As far as I can see from your code, the object cmd isn't needed. You create a command object but don't set any properties and it's never used (hopefully a compiler warning if it's turned on). Maybe you thought you would fill the dataset from a command object? Can't be done...

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

The dataset (test) was generated from the OleDbAdapter (Configure this adapter...) in VS.Net. This is the place where I created the sql query using a combination of the Query Builder and some custom sql. I see your point about how cmd line is not needed. :)

 

From here, I establish a connection, call the fill for the dataset (test), and then attempt to put the dataset into a table and display it.

 

Is this the way to view the dataset?

 

Thanks.

 

Karl

  • *Experts*
Posted

Binding a DataGrid to a DataSet is one way to view the data, sure. You can also use test.GetXml() to return a string of the XML version of the data. You could write it to a file with test.WriteXml(...) or just use something like "Debug.WriteLine(test.GetXml())" to view the XML in the Output window.

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Back for more...;)

 

At this point in our application development, I am not yet ready to work with xml but it is definatly a consideration for the future.

 

Here's what I am doing:

 

----------------

mscuhdbConn1 = New OleDb.OleDbConnection(conn)

 

'(2)Dim custTables As DataTable = test.Tables.Add("New")

 

OleDbDataAdapter.Fill(test)

 

(1)ComboBox2.DataSource = test

(1)ComboBox2.DisplayMember = "site"

 

<OR>

 

(2)Dim dv As DataView = New DataView(test)

(2)ComboBox2.DataSource = dv

(2)ComboBox2.DisplayMember = "site"

 

----------------

 

The result of the #1 is that System.Data.DataViewManagerListItemTypeDescriptor message.

 

The result of the #2 doesn't do anything. Before I had tried creating a new table but I didn't have much luck with that.

 

Suggestions?

 

Thanks a bunch.

 

Karl

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...