Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-02-2010
Member
 
Join Date: Aug 2006
Posts: 122
How to Get the values from the database in ASP?

I have started doing the ASP three months back. Now I can do some programs pretty well. I have also made a form in ASP. The main problem I am facing is while getting the values from the database. Along with that I want to put that values into the Listbox. Can anyone tell me how to get the values from the database in ASP? Please help me as soon as possible.!!
__________________
As you simplify your life, the laws of the universe will be simpler; solitude will not be solitude, poverty will not be poverty, nor weakness.Henry David Thoreau
Reply With Quote
  #2  
Old 03-02-2010
Member
 
Join Date: Nov 2008
Posts: 996
Re: How to Get the values from the database in ASP?

I am assuming that you are using the Microsoft Access as a database. You will have to choose 'Blank Access Database' from the starting menu, to create a database after opening Microsoft Access. After creating the database, you will have to enter the data that has to be tested by creating the web page to display. After writing the HTML coding, you will have to write down the code for ASP to connect to the database, which will look similar like this :
Code:
<%

Dim adoCon         
Dim rsGuestbook    
Dim strSQL

Set adoCon = Server.CreateObject("ADODB.Connection")

%>
Reply With Quote
  #3  
Old 03-02-2010
Member
 
Join Date: Aug 2006
Posts: 235
Re: How to Get the values from the database in ASP?

Before connecting the database to the ASP, you should add something to your database. After adding the data you can connect the database to ASP. After doing this you will need to create a page to display the contents of the database. Because once the contents are displayed, you can select which entry you want to update. The following form will help you a lot :
HTML Code:
<html>
<head>
<title>Selected Entry gets Updated</title>
</head>
<body bgcolor="grey" text="black">
<%
Dim adoCon          
Dim rsGuestbook    
Dim strSQL       

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Update.mdb")

Set rsupdate = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT tblComments.* FROM tblComments;"
rsupdate.Open strSQL, adoCon
Do While not rsupdate.EOF

     Response.Write ("<br>")
     Response.Write ("<a href=""update_form.asp?ID=" & rsupdate("ID_no") & """>")
     Response.Write (rsupdate("Name")) 
     Response.Write ("</a>")
     Response.Write ("<br>")
     Response.Write (rsupdate("Comments"))
     Response.Write ("<br>")

     rsupdate.MoveNext

Loop

rsupdate.Close
Set rsupdate = Nothing
Set adoCon = Nothing
%>
</body>
</html>
__________________
3.2 (northwood)
2gig ram
ATI AIW X800xt 256mb
Gigabyte GA-8knxp 875p Chipset
Optiwrite 8X DVD Burner
Win XP PRO Sp2 (Works Perfectly)
2 SATA Raptor 74gig Raid 0
2 7200 IDE 320gig HD
Reply With Quote
  #4  
Old 03-02-2010
Member
 
Join Date: Aug 2006
Posts: 227
Re: How to Get the values from the database in ASP?

I am trying to tell the steps that are involved while creating the database. First you will have to create an ODBC DSN on Your Web Server. For creating
an ODBC Data Source Name, you can use the ODBC Administrator which is present in the Control Panel. The reason behind creating that is the ODBC Administrator allows you to create and manage ODBC DSNs. A System DSN is available to your ASP page even if no user is logged on the machine. Then you will have to generate your ASP Page to Access the Database. After doing this you can able to get the values from the database.
__________________
I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.
Reply With Quote
  #5  
Old 03-02-2010
Member
 
Join Date: Jul 2006
Posts: 286
Re: How to Get the values from the database in ASP?

I think I have got the perfect code for you. The following code connects the database and takes the values from the table and stores it in a recordset which is rsValues in the coding. After that the values are added in to the option form. For doing this I have also used the do...loop. Here is the coding :
Code:
<%
set objConn=server.createobject("adodb.connection")
objConn.open "DSN=dbDSN;uid=username;pwd=pass"
set rsValues=objConn.execute("select field from table where )
%>
<Form>
<Select>
<%
do while not rsValues.eof %>
<option> <%=rsValues(0)%> </option>
<%
rsValues.movenext
loop
rsValues.close
set rsValues = nothing
objConn.close
set objConn=nothing
%>
</Select>
</form>
__________________
IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....
Reply With Quote
  #6  
Old 03-02-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to Get the values from the database in ASP?

You can also use the code that is described as follows. The code for the trial.asp is shown below :
HTML Code:
<%@Language=VBScript %>
<HTML>
<BODY>
<%
  Dim Connect ,RS, Query, Details
  Details = Trim(Request("Trial"))

  Set Connect = Server.CreateObject("ADODB.Connection")
  Connect.Open "Catalog"

  Set RS = Server.CreateObject("ADODB.Recordset")

  Query = "SELECT * FROM Items "
  Query = Query & "WHERE ItemType='"& Details & "' "
  Query = Query & "ORDER BY [ItemName]"
 
  Set RS = Conn.Execute(Query)

  If RS.EOF Then
    Response.Write "There are no Details available for " & Request("Details")"
  Else
%>
<table border="1" width="100%" cellpadding="2">
<tr>
<td><strong><font face="Arial" size="2">Name</font></strong></td>
<td><strong><font face="Arial" size="2">Product Type</font></strong></td>
<td><strong><font face="Arial" size="2">Details</font></strong></td>
<td><strong><font face="Arial" size="2">Price</font></strong></td>
</tr>
<%
  Do While Not RS.EOF
%>
<tr>
<td><font face="Arial" size="2"><% = RS("Name") %></font></td>
<td><font face="Arial" size="2"><% = RS("ProductType") %></font></td>
<td><font face="Arial" size="2"><% = RS("Details") %></font></td>
<td><font face="Arial" size="2"><% = RS("Price") %></font></td>
</tr>
<%
    RS.MoveNext

  Loop
%>
</table>
<%
  End If

  RS.Close
  Set RS = Nothing
  Conn.Close
  Set Conn = Nothing
%>
</BODY>
</HTML>
You can modify it accordingly.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Get the values from the database in ASP?"
Thread Thread Starter Forum Replies Last Post
W32 registry values are not getting matched by the default values Angrzej Networking & Security 5 19-05-2011 12:23 PM
Increasing primary key values in database Aileen_L Software Development 4 06-02-2010 04:28 PM
Creating Database link in database Lachlann Software Development 3 28-01-2010 01:17 PM
How to write the form values in Database using C# Aienstaien Software Development 3 20-08-2009 03:36 PM
convert filemaker pro database to access database Czack MS Office Support 3 15-04-2007 01:06 AM


All times are GMT +5.5. The time now is 06:42 PM.