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

Populate a ListBox in an Winforms application using ado.net.

1
I have to populate a listbox with details of a particular customer.
For example, you may want to view a Customer with the current products for that Customer. List Box should display the current prouct name registered by that customer.
Here goes my try,
Form1.cs:
private void ProductsRegistered(string UserName, string productID)
{
UserData.ProductsRegistered proreg = userdata.GetRegisteredProducts(UserName, productID);

listBox1.DataSource = proreg;
listBox1.DisplayMember = proreg.ProductName;
}

userdata.cs:
public struct ProductsRegistered
{
public string ProductID;
public string ProductName;
}

public ProductsRegistered GetRegisteredProducts(string UserName, string ProductID)
{

ArrayList arlist = new ArrayList();
ProductsRegistered proreg = new ProductsRegistered();
DataTable dtUsers = new DataTable();
string strSQL = "SELECT DISTINCT a.UserID,a.ProductID,b.[Name] FROM myacc_userregisteredProducts a inner join InstallationProduct b on a.ProductID=b.[ID]inner join myacc_users c ON a.UserID=c.[ID]WHERE c.UserName ='" + UserName + "'";
SqlConnection sqlConn = new SqlConnection("server=Intra; database=vc; uid=sa; pwd=ore");
sqlConn.Open();
SqlCommand cmd = new SqlCommand(strSQL, sqlConn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{

proreg.ProductID = dr[0].ToString();
proreg.ProductName = dr[1].ToString();

}
dr.Close();
sqlConn.Close();
//listBox1.DataSource = proreg;
//listBox1.DisplayMember = "productName";

}

Help is appreciated!Thanks in Advance!
Nov 20 '07 #1
1 1549
nateraaaa
663 Expert 512MB
You need to call listbox1.DataBind() to bind your datasource to your listbox control.

Nathan
Nov 20 '07 #2

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

Similar topics

2
by: James Goodman | last post by:
I have a listbox named sub1 on an asp page. I need to fill this list with values from a table. These are selected based upon the selection of a value/s in another listbox. It was suggested that I...
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: Yakimo | last post by:
I have a very simple application, consisting of a form and a listbox on it. I would like automatically to populate the listbox after the form is loaded and displayed, not using a button. But if I...
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...
2
by: =?Utf-8?B?U3RlcGhlbiBSaXRjaGll?= | last post by:
Hi NET1.1 / Winforms I have a listbox that I am binding to a table via the DataSource property. However I want to be able to programmatically select values in this listbox so I am using the...
6
by: Spoogledrummer | last post by:
Hi, I'm a total novice to ASP (yesterday was literally the first time I looked at it) but am currently working on an application that will send an e-mail to selected users, the text that goes in the...
1
by: Chaihana Joe | last post by:
Hi I'm trying to populate a listbox as a value list in code (access 2003). Unfortunately I'm getting 'runtime error 2176 - the setting for this property is too long' somewhere around the 2000...
2
by: dbuchanan | last post by:
I intend to populate a listBox from the database for later use. (the intent for doing this is irrelevant to this questrion) The list box when hidden is never populated. The list box when visible...
3
by: itisthiyagu | last post by:
Hi, Im looking for ListBox which works like Windows-XP's Add/Remove programs listbox. where can i get this kind of listbox ? I want to show a text in ListItem & it should expand with its...
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:
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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.