473,803 Members | 3,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 ProductsRegiste red(string UserName, string productID)
{
UserData.Produc tsRegistered proreg = userdata.GetReg isteredProducts (UserName, productID);

listBox1.DataSo urce = proreg;
listBox1.Displa yMember = proreg.ProductN ame;
}

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

public ProductsRegiste red GetRegisteredPr oducts(string UserName, string ProductID)
{

ArrayList arlist = new ArrayList();
ProductsRegiste red proreg = new ProductsRegiste red();
DataTable dtUsers = new DataTable();
string strSQL = "SELECT DISTINCT a.UserID,a.Prod uctID,b.[Name] FROM myacc_userregis teredProducts a inner join InstallationPro duct 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(strS QL, sqlConn);
SqlDataReader dr = cmd.ExecuteRead er();
if (dr.Read())
{

proreg.ProductI D = dr[0].ToString();
proreg.ProductN ame = dr[1].ToString();

}
dr.Close();
sqlConn.Close() ;
//listBox1.DataSo urce = proreg;
//listBox1.Displa yMember = "productNam e";

}

Help is appreciated!Tha nks in Advance!
Nov 20 '07 #1
1 1568
nateraaaa
663 Recognized Expert Contributor
You need to call listbox1.DataBi nd() 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
4943
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 use a hidden iframe on my main page, & carry out the processing inside the frame, using jscript. If I open the page in a browser, & make a selection in the first listbox (named main), the data in the frame appears to be processed correctly, the...
2
6129
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 collection of status values. If I later pull an item record from the dataset into this item maintenance screen I cannot seem to get the status value that is contained in the dataset to display on the form, it displays the first value in the listbox...
2
382
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 put my code in Load event, the form is not shown until after the listbox is populated. Because populating the listbox is not fast in my case, I also would like the list items to be visible after I insert them one by one, not at the end when the...
1
1964
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 page is submited / postback, the listbox is still empty. Do you have any solution for this case (if I still want to use ListBox Server Control) ?
2
5548
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 code below... With lstJobTypes .DataSource = BusinessRules.Common.JobTypes.All(True)
6
2210
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 e-mail will be displayed in a textarea and will be loaded from the database but is editable. The text loaded into the textarea will be selected from a select listbox which is populated by the database (I've actually managed to figure that bit out). ...
1
5834
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 character mark. Searching on the web I've seen mention that there is a limit of 2048 characters for a value list and that a workaround is to use a function
2
1511
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 is always populatd. How do I populate it even though it remains hidden? Thanks, Doug
3
1580
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 description when user selects a particular item. Also i want to add a button into to ListItem. it is same like Add/Remove programs ListBox. anybody help me. -Thiyagu
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6842
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.