Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to access recordsets using javascript 1

Status
Not open for further replies.

bryant89

Programmer
Nov 23, 2000
150
CA
I need to see an example of how to access a recordset using javascript. I can do it usint vb and dtc's but I have no idea when it comes to javascript

If anyone could give me a site to go to for examples or even an example they have that would be great
 
Here is one way that works, there are any number of different techniques that you can use to work with ADODB Objects.

var conn = Server.CreateObject("ADODB.Connection");
conn.Open("dsn=ftwebdocs");
var rs = Server.CreateObject("ADODB.Recordset");
rs.Open("select Title, FlashDate, Name, DocTypeDI from mytable", conn, 1,3,1);

while( !rs.EOF){
Response.Write( rs(&quot;Title&quot;) + &quot;: &quot; + rs(&quot;Name&quot;) + &quot;<br>&quot;);
rs.MoveNext();
}

rs.Close();
conn.Close()
rs = null;
conn = null;

Hope this helps
-pete
 
Right on, I will try this out. I have a few questions though about what parameters I have to change I have highlited things I need clarification on.


var conn = Server.CreateObject(&quot;ADODB.Connection&quot;);
conn.Open(&quot;dsn=ftwebdocs&quot;);
var rs = Server.CreateObject(&quot;ADODB.Recordset&quot;);
rs.Open(&quot;select Title, FlashDate, Name, DocTypeDI from mytable&quot;, conn, 1,3,1);

while( !rs.EOF){
Response.Write( rs(&quot;Title&quot;) + &quot;: &quot; + rs(&quot;Name&quot;) + &quot;<br>&quot;);
rs.MoveNext();
}

rs.Close();
conn.Close()
rs = null;
conn = null;


The reason I need to loop through a recordset is to get the directory path of certain images that are stored in fields in the table. So each time I loop through the recordset I need to save the value retrieved into a seperate variable. Then pass these variables to a seperate function to set my source values of 3 different images that are retrieved from the recordset. I hope this makes sense.

I have to add again that I appreciate all of your help
 
> conn.Open(&quot;dsn=ftwebdocs&quot;);

DSN = Data Source Name. Are you familiar with them? You use the OLE32 Control Panel Applet to create them. They hold the connection information to your data source.

> get the directory path of certain images that are stored in fields in the table

You should be able to generate a SQL statement that will retrieve only the rows contianing the images of interest. This should keep you from having to 'search' through the returned recordset.

The in your while loop just replace:
Response.Write( rs(&quot;Title&quot;) + &quot;: &quot; + rs(&quot;Name&quot;) + &quot;<br>&quot;);

with whatever HTML you need, OR even use inline ASP replacement style code, i.e.:

<%
while( !rs.EOF){
%>
<div><%=rs(&quot;Title&quot;)%><span class=&quot;foo&quot;><%=rs(&quot;Name&quot;)%></span></div>

<%
rs.MoveNext();
}
%>

Hope this helps
-pete
 
I cant use ASP replacement code within javascript tags

ie
<script language=&quot;JavaScript1.2&quot;>
// slide show
function reapply()
{
setTimeout(&quot;slideit()&quot;,2000)
return true
}
window.onerror=reapply
</script>
<script language=&quot;JavaScript1.1&quot;>
<!--
var image1=new Image()
image1.src=&quot;<%../MemberImages/ProjPics/13-5-1.jpg %>&quot;
var image2=new Image()
image2.src=&quot;../MemberImages/ProjPics/13-5-2.jpg&quot;
var image3=new Image()
image3.src=&quot;../MemberImages/ProjPics/13-5-3.jpg&quot;
//-->
</script>

the asp style is not recognized. Do you have an email address I could get from you or a chat program that u run. So I can explain to you better what I am trying to do.
 
You are missing the 'equal' siqn and you need a variable or object inside the ASP replacment statement:

<% var sImageOne = ... // whatever %>

image1.src=&quot;<%=sImageOne%>&quot;


pete@albano.reno.nv.us
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top