asp.net consultancy chorley ASP.NET Server Side Scripting Wigan
Website Development Radcliffe

IT Services And Support

Email : ren@techsolus.co.uk
Mobile Phone : 0788 68 41 411
Answerphone : 01204 469683
bespoke invoice systems Standish Information Technology Advice Worsley
    development systems Ramsbottom
data manipulation Farnworth access databases Whitefield SQL connections Atherton
online accessible software Leyland software compatible Coppull


Get connected and Online Tottington
remote management Makerfield code and design Aspull

ASP.Net Dropdownlist From SQL (Access mdb) - 20/10/2011

If you've read any other bit from this blog you'll know I like Access...small...simple...easy.  Drop down lists can be populated from the results from an access database query.  So in the code section you'd do something like...

dim qwe as string
qwe = "SELECT myfield1, myfield2 FROM mytable"

dim dbconn as New OleDbConnection ("Provider = Microsoft.Jet.OLEDB.4.0; data source = c:\myfolder\mydatabase.mdb")
dim dbread as oledbdatareader
dim runcommand as new oledbcommand

dbconn.open

runcommand = new oledbcommand(qwe, dbconn)
dbread = runcommand.executereader

mydropdownlist.datasource = dbread
mydropdownlist.datatextfield = "myfield1"
mydropdownlist..datavaluefield = "myfield2"
mydropdownlist.databind

dbconn.close
dbread.close

So that's the code bit, in the page you'd need the following

<asp:dropdownlist id = "mydropdownlist" runat = "server" />

The only real thing to note is the "datatextfield" and "datavaluefield", so the text is what is displayed in the list and the value is the sort of "hidden" value bit.  If you're retrieving the value, or text, of the dropdownlist then in the code its...

mydropdownlist.selectedvalue

or

mydropdownlist.selecteditem.text

Post A Comment

Name Comment
programming services asp.net specialist
Valid XHTML 1.0 Transitional
Admin
GD