Populating a ListBox from a database using VB.NET 1.1

Hi,

I've been racking my brain trying to do a simple task of populating a listbox from a table in a sqlserver database.
From trawling the web I have found that nearly all examples show population of the listbox via an array. Also they show you need to databind the listbox. However the only attribute I can find is databindings.
What I have managed to get working is the listbox text to be populated but not the value.
(SEE CODE BELOW).
I've spent 2 days trying to solve it and am thinking of giving up rewritting the whole project in C# which is what I code in normaly anyway.
Oh and one more thing - I'm writing this program as a VB.NET Windows application using MS Visual Studio.NET 2003 and not as a web page.
Any help would be fab.
Thanks in advance.
Matt.

Dim strConn As String = "server='12.34.56.78'; user id='test'; password='test1'; Database='testdbms'"
Dim myConnection As New SqlConnection(strConn)
Dim datareader As SqlDataReader
Dim strSQL As String = "select pasid,scriptname from prizeallocationscripts"
Dim myCommand As New SqlCommand(strSQL, myConnection)
Dim i = 0

' LBGame is a list box on Windows form.
LBGame.DisplayMember = "scriptname"
LBGame.ValueMember = "pasid"
' LBGame.DataBind() -- There is no databind property for this listbox

myConnection.Open()
datareader = myCommand.ExecuteReader()
While datareader.Read()
LBGame.Items.Add(datareader.Item(1))
LBGame.SetSelected(i, True)
LBGame.SelectedValue = datareader.Item(0) ' I'm trying to populate the value here but it just doesn't want to know.
i = i + 1
End While
myConnection.Close()
0
ItTakesTime
2/16/2004 12:17:27 PM
asp.net.visual-basic.net 3721 articles. 0 followers. Follow

1 Replies
847 Views

Similar Articles

[PageSpeed] 50

Try

LBGame.Items.Add(new ListItem(datareader.Item(1), datareader.Item(0)) 

HTH
Comment the other two lines i.e for setSelected and selectedvalue
Sushila Bowalekar Patel
Visual ASP/ASP.NET MVP
http://weblogs.asp.net/sushilasb
0
SushilaSB
2/19/2004 7:09:56 PM
Reply:

Similar Artilces:

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

Problems while porting .Net framework 1.0 (VB.Net) application to .Net Framework 1.1
Hello,   I have a ASP.Net web application,written in VB.Net,developed on .Net Framework 1.0 .I am trying to port it on to .Net framework 1.1.   For achieving this,I follow the following steps-   1.Open the project using the .vbproj file. 2.I am prompted with the conversion message "Do you want to convert the solution and all projects to .Net framework  1.1....." 3.I click "Yes" 4.I assume that the project is now converted. 5.I build the project & try to run it. 6.I get the following error -     Server Error in '/Consert.Net' Application. ...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

Using Visual Studio.NET 2005 with .NET Framework 1.1
I'm wondering how easy it is to use Visual Studio.NET 2005 to develop with the .NET Framework 1.1. The 2005 IDE is superior to the VS 2003 IDE (especially in terms of HTML editing), and I would like to switch over in the future. However, my project is not quite ready to be converted to .NET 2.0. Can anyone direct me to an article on this or have any advice? Thanks, Allen K. There are 10 types of people in this world: those that understand binary and those that don't. Did you get an answer to this one? I would like to know the same..Thanks! The VS 2005 IDE was created to...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

is .net framework 1.1 same as .net framework SDK 1.1
is .net framework 1.1 same as  .net framework SDK 1.1 Basically Framework 1.1 of .NET includes the Sofware Development Kit (SDK) 1.1 http://www.microsoft.com/downloads/details.aspx?FamilyID=9b3a2ca6-3647-4070-9f41-a333c6b9181d&displaylang=en Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET I think .net framework 1.1 is just the runtime library to view .net 1.1 programs.  the .net framework SDK 1.1 one is the actual development library used to create them.   Eri...

Why Visual Studio 2005 ask me to convert a solution already got converted Somebody did the conversion of a solution from .net 1.1 to .net 2.0 by using the automatic conversion wizard of Visual Stu
Why Visual Studio 2005 ask me to convert a solution already got converted Somebody did the conversion of a solution from .net 1.1 to .net 2.0 by using the automatic conversion wizard of Visual Studio 2005. Then, he changed to another company. Now, I take over his job. Unfortunately, when I attempted to open that solution, Visual Studio 2005 prompted me the conversion wizard again to forced me to perform a conversion on the solution. Does someone know why?--Harish Patel www.MicrosoftSQLandASP.netpatelharish@gmail.com Hi, How many projects are in the solution, does it have UNLOADE...

Using .net 2.0 ws in .net 1.1
Hi,I have a ws written in 2.0 that returns a dataset. I need to use this ws in .net 1.1. Seems like having the ws returning typed datasets causing a problem.I am using c# for the ws. Does anyone have any idea ? Any suggestion would be appreciated. Thanks, recruit A web service should be indifferent to which version of ASP.NET is producing and which version is consuming. Please post any error messages and the wsdl produced by the 1.1 consumer. Have you loaded WSE 3.0 (http://www.microsoft.com/downloads/details.aspx?familyid=018a09fd-3a74-43c5-8ec1-8d789091255d&displaylang=en) and mon...

is it possible to use .net 1.1 with VS.NET 2002?
Is it at all possible to use .net framework 1.1 with vs.net 2002 i.e. the original VS.NET? or do i have to upgrade to vs.net 2003 to take advantage of the intellisense of new properties/methods etc. that 1.1 offers? Thanks,Kulin Parikh -- The more I learn about the Internet, the more amazed I am that it works at all. I upgraded the framework to 1.1 and had no problems, everything worked fine on VS.NET 2002. How exactly did you upgrade? I had a **** problem. After i installed .net 1.1, it still took the .net 1.0 files as the default even after running aspnet_regiis -ua and aspnet_reg...

.NET 1.1, RadioButtonLists, and assigning eventhandlers in VB.NET
I actually have to write this in VB.NET using the old 1.1 framework.  What I am doing is creating my radiobuttonlists in the codebehind while adding them to a panel's control collection at runtime.  I need to assign a method, ie. SelectionChanged(object as sender, e as eventargs), at runtime in the codebehind but am having a hell of a time doing it.  In C# I would just assign rbl.SelectedIndexChanged += new EventHandler(SelectionChanged) and be done with it but it doesn't seem that simple in VB.NET.  I haven't done VB is quite a while so any help would be MUCH...

Using .NET 1.1 dll in .NET 2.0
I have my old application on Visual Studio 2003, now we are planning to migrate to Visual Studio 2005, so is there a way to use my old dlls as references that were built using .NET Framework 1.1 in a new application that will be built using .NET Framework 2.0? I also have a question regarding the posibility to build code that was written in Visual Studio 2003 environment using .NET Framework 2.0 compiler?Mohammad Abu-AliMicrosoft Certified Professional Hi, Yes you can use your .NET 1.1 dll in your 2.0 app (but the other side is not true) For the last question, there is great chance...

Where is the ADO.NET Sybase driver for .NET 1.1 and .Net 2.0?
Hi All Does anyone know where I can get the Sybase drivers for ADO.NET for both versions, 1.1 and 2.0/3.0? Cheers Chris Burrell Hi Chris, There is no release of ASE ADO.NET Provider 2.0 (I assume you refer to ASE provider, not ASA - if ASA please port to sybase.public.sqlanywhere.general). For the 1.1 Provider: It is available in the ASE SDK for windows or the PC Client CDRom included with ASE product. On the SDK its available as 12.5.1 and 15.0 On ASE PC Client I think 12.5.1 is part of ASE 12.5.X and 15.0 is part of ASE 15.X 2.0 provider should release som...

Does Visual Studio .NET 2003 (version 7.1.3088) & NET Framework 1.1 support AJAX ?
Dear friend, 1. Does Visual Studio .NET 2003 (version 7.1.3088) & NET Framework 1.1 support AJAX ? 2.  i don't know if i can implement AJAX for my case below ? pls advise... i have built a windows application to connect to a card reader DLL,   but right now i have to build it for web application..and it's a real challenge since i have blank idea...   i also write the source code for the windows application below , for analysis...   the case is like these : --------------------------1. we have a card reader (usb port connection)...   2. we must connect...

Porting VB.Net application to .Net Framework 1.1
Hello,   I have a ASP.Net web application,written in VB.Net,developed on .Net Framework 1.0 ,which,I am trying to port on to .Net framework 1.1.   For achieving this,I follow the following steps-   1.Open the project using the .vbproj file. 2.I am prompted with the conversion message "Do you want to convert the solution and all projects to .Net framework  1.1....." 3.I click "Yes" 4.I assume that the project is now converted. 5.I build the project & try to run it. 6.I get the following error -     Server Error in '/Consert.Net' Appli...

Web resources about - Populating a ListBox from a database using VB.NET 1.1 - asp.net.visual-basic.net

Koalas over-populating Great Ocean Road 'fell out of trees due to starvation'
A koala expert says the culling of more than 700 koalas was necessary because they were "falling out of the trees due to starvation".

Apple begins populating international iBookstores - iLounge News
According to a report from Italian language iPadevice (Translated Link), Apple has begun populating the iBookstores of Australia, Canada, France, ...

Disney is populating their theme parks with robots that can THROW THINGS AT YOU
Disney is hard at work bringing about the Robopocalypse. Behold the throwing bots, the brand-new batch of robots Disney can't wait to unleash ...

Cavuto on Bartiromo at FBN: ‘We’re Populating it with Italians’
Neil Cavuto went on Brian Kilmeade ‘s Fox News Radio show today to talk about the addition of Maria Bartiromo to the FBN line-up. “We’re populating ...

Starbucks Plans to Begin Populating India at Last
Starbucks, the popular American coffee retailer, plans to open its first store in India in September through a joint venture with Tata Global ...

American cougars are re-populating their historical range
American mountain lions, or cougars, are re-emerging in areas of the United States, reversing 100 years of decline. The evidence, [...

Cougars are re-populating their historical range, new study confirms
American mountain lions, or cougars, are re-emerging in areas of the United States, reversing 100 years of decline. The evidence raises new conservation ...

Populating DeLong: Long Form
I have now populated [DeLong: Long Form](http://delong.typepad.com/delong_long_form/) from the present back through the start of 2012for those ...

Cougars are re-populating their historical range, new study confirms
American mountain lions, or cougars, are re-emerging in areas of the United States, reversing 100 years of decline. The evidence, published in ...

Seattle’s unlikely hero? How RealNetworks sparked the region’s startup community
... such as Amazon.com and Microsoft. But the DNA of another company has had a surprising impact on the Seattle startup ecosystem, populating dozens ...

Resources last updated: 2/8/2016 1:23:02 PM