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

How I populate Listbox with dataset?

Hello

I've created a class that has a method that returns a dataset like this:

public DataSet GetAllCustomers()

{

Open();

DataSet ds = new DataSet();

SqlDataAdapter da = new SqlDataAdapter();

da.SelectCommand = new SqlCommand("CustListAll", dbconn);

da.Fill(ds);

return ds;

}

Then I added a new project and then tried to do this:

public Form1()

{

InitializeComponent();

Northwind n = new Northwind();

listBox1.DataSource = n.GetAllCustomers();

listBox1.DisplayMember = "CustomerName";

listBox1.Text = "CustomerName";

}

When I run it only has a text
"System.Data.DataViewManagerListItemType.Descripto r" in it

errrm? :) what to do here to get it to show in listbox?

/Lasse


Nov 17 '05 #1
3 33695
Hi,

My advise is you to read about bind in windows forms, google: windows forms
data bind

You need to especify the table from where the columns will come from, I got
this piece of code from the first link in the above search

private DataViewManager dsView;
private DataSet ds;

dsView = ds.DefaultViewManager;

// Combobox Databinding
cbCust.DataSource = dsView;
cbCust.DisplayMember = "Customers.CompanyName";
cbCust.ValueMember = "Customers.CustomerID";

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:ek*************@TK2MSFTNGP15.phx.gbl...
Hello

I've created a class that has a method that returns a dataset like this:

public DataSet GetAllCustomers()

{

Open();

DataSet ds = new DataSet();

SqlDataAdapter da = new SqlDataAdapter();

da.SelectCommand = new SqlCommand("CustListAll", dbconn);

da.Fill(ds);

return ds;

}

Then I added a new project and then tried to do this:

public Form1()

{

InitializeComponent();

Northwind n = new Northwind();

listBox1.DataSource = n.GetAllCustomers();

listBox1.DisplayMember = "CustomerName";

listBox1.Text = "CustomerName";

}

When I run it only has a text
"System.Data.DataViewManagerListItemType.Descripto r" in it

errrm? :) what to do here to get it to show in listbox?

/Lasse

Nov 17 '05 #2
hmm k,

changing to:

listBox1.DataSource = n.GetAllCustomers().DefaultViewManager;

didnt help much either :(

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uW**************@TK2MSFTNGP15.phx.gbl...
Hi,

My advise is you to read about bind in windows forms, google: windows forms data bind

You need to especify the table from where the columns will come from, I got this piece of code from the first link in the above search

private DataViewManager dsView;
private DataSet ds;

dsView = ds.DefaultViewManager;

// Combobox Databinding
cbCust.DataSource = dsView;
cbCust.DisplayMember = "Customers.CompanyName";
cbCust.ValueMember = "Customers.CustomerID";

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:ek*************@TK2MSFTNGP15.phx.gbl...
Hello

I've created a class that has a method that returns a dataset like this:

public DataSet GetAllCustomers()

{

Open();

DataSet ds = new DataSet();

SqlDataAdapter da = new SqlDataAdapter();

da.SelectCommand = new SqlCommand("CustListAll", dbconn);

da.Fill(ds);

return ds;

}

Then I added a new project and then tried to do this:

public Form1()

{

InitializeComponent();

Northwind n = new Northwind();

listBox1.DataSource = n.GetAllCustomers();

listBox1.DisplayMember = "CustomerName";

listBox1.Text = "CustomerName";

}

When I run it only has a text
"System.Data.DataViewManagerListItemType.Descripto r" in it

errrm? :) what to do here to get it to show in listbox?

/Lasse


Nov 17 '05 #3
Hi,

Did you put the other lines?
even as you only have one table you may get need to indicate which table the
columns refer to

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:Oh*************@TK2MSFTNGP10.phx.gbl...
hmm k,

changing to:

listBox1.DataSource = n.GetAllCustomers().DefaultViewManager;

didnt help much either :(

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message news:uW**************@TK2MSFTNGP15.phx.gbl...
Hi,

My advise is you to read about bind in windows forms, google: windows

forms
data bind

You need to especify the table from where the columns will come from, I

got
this piece of code from the first link in the above search

private DataViewManager dsView;
private DataSet ds;

dsView = ds.DefaultViewManager;

// Combobox Databinding
cbCust.DataSource = dsView;
cbCust.DisplayMember = "Customers.CompanyName";
cbCust.ValueMember = "Customers.CustomerID";

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Lasse Edsvik" <la***@nospam.com> wrote in message
news:ek*************@TK2MSFTNGP15.phx.gbl...
> Hello
>
> I've created a class that has a method that returns a dataset like
> this:
>
> public DataSet GetAllCustomers()
>
> {
>
> Open();
>
> DataSet ds = new DataSet();
>
> SqlDataAdapter da = new SqlDataAdapter();
>
> da.SelectCommand = new SqlCommand("CustListAll", dbconn);
>
> da.Fill(ds);
>
> return ds;
>
> }
>
>
>
> Then I added a new project and then tried to do this:
>
>
>
> public Form1()
>
> {
>
> InitializeComponent();
>
> Northwind n = new Northwind();
>
> listBox1.DataSource = n.GetAllCustomers();
>
> listBox1.DisplayMember = "CustomerName";
>
> listBox1.Text = "CustomerName";
>
>
>
> }
>
>
>
> When I run it only has a text
> "System.Data.DataViewManagerListItemType.Descripto r" in it
>
> errrm? :) what to do here to get it to show in listbox?
>
>
>
> /Lasse
>
>
>
>



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Wishing I was skiing mom | last post by:
Newbie to VB .NET. My solution contains an item maintenance screen, one of the fields on the screen is an item status, this field is defined as a listbox. The listbox item property contains a...
2
by: James McGivney | last post by:
In a C# program I have an SQL database. A data adapter is connected to the database and a dataset has been generated. I would like to populate a listBox (or comboBox) from the dataset such that...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
3
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to...
1
by: Devin Wood | last post by:
Hi, I have a page with a ListBox on it, and It's also have a some buttons to populate the ListBox by using JavaScript. I have no problem with populate the listbox using JavaScript. But when the...
5
by: Dave | last post by:
Hi All, I have a windows form that contains 2 listboxes and 2 buttons. The listbox on the right is populated by a database routine (This is the easy part). The listbox on the left is populated...
1
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to...
3
by: Robert W. | last post by:
I have a SQL Server table called "ClosedMonths" that contains two pertinent fields: Yearx Monthx 2000 1 2000 2 2000 3 I want to simply query this...
4
by: Joe Blow | last post by:
Folks, I have read all the posts about databases I could find and I think I need a little more help. I want to take all the items from a field in an access database and use them as list items in...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.