By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,196 Members | 1,682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,196 IT Pros & Developers. It's quick & easy.

Retrive record from database in combobox

P: 1
I want to rerive the record from database table into combobox.Plz do reply me how should i do this in ASP
Apr 2 '08 #1
Share this Question
Share on Google+
1 Reply


jeffstl
Expert 100+
P: 432
I want to rerive the record from database table into combobox.Plz do reply me how should i do this in ASP
This code assumes you have set up a database connection string called dbconn. Also I am using ADODB in this example which works well with MS Access.

I am also assuming you are talking about classic ASP in the first example .

If you need help with connection strings www.connectionstrings.com

Expand|Select|Wrap|Line Numbers
  1.  
  2. dim ComboRS,ComboSQL
  3. Set ComboRS = Server.CreateObject("ADODB.Recordset")
  4. ComboSQL = "Select column_name from MyTable"
  5. ComboRS.Open ComboSQL , dbconn, adOpenStatic
  6.  
  7. While not EquipRS.EOF
  8.      response.write "<option>" 
  9.      response.write ComboRS ("column_name")
  10.      response.write "</option>"
  11.      ComboRS.MoveNext
  12. wend
  13.  
  14. ComboRS.Close
  15. Set ComboRS = Nothing
  16.  
  17.  
If you are referring to .NET this is the code.
You just bind your drop down box to a datareader. This assumes you have a database conenction set up called DBConnection.
Expand|Select|Wrap|Line Numbers
  1. dim dropdownsql ,dropcomm,dropread
  2. dropdownsql = "Select column_name From MyTable"
  3. dropcomm=New OleDbCommand(dropdownsql,DBConnection)
  4. dropread=dropcomm.ExecuteReader()
  5. DrpDwnID.DataSource=dropread
  6. DrpDwnID.DataBind()
  7.  
Apr 2 '08 #2

Post your reply

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