Results 1 to 6 of 6

Thread: How to to use an Access DB file in asp?

  1. #1
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default How to to use an Access DB file in asp?

    How to to use an Access DB file in asp?

    OK, I have an Access DB file, with a table name BooksInfo. The table looks like this.
    Code:
    Title                                Publisher    Rating    Popularity    PicPath               PreviewPath                   BookPath                 
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    ASP.Net Kick Start                   SAMS         5         45            C:\ASPNETKS.bmp       C:\ASPNETKSsampchap.htm       C:\ASPNETKScontent.htm   
    Teach Yourself ASP.Net in 21 Days    SAMS         5         78            C:\TYASPNET21D.bmp    C:\TYASPNET21Dsampchap.htm    C:\TYASPNET21Dcontent.htm
       .
       .
       .
    string                               string       int       int           string                string                        string
    and I want a html output from ASP like this.
    HTML Code:
    <html>
      <head>
        <title>Books - Preview Page</title>
      </head>
      <body bgcolor="#ffccff" link="#000099" vlink="#000033">
        <TABLE id="Table1" cellSpacing="3" cellPadding="5" border="10" align="center">
        <TR>
          <TD>
            <P>
              <STRONG><FONT size="5"><A href="file:///\\MyMachine\C\ASPNETKScontent.htm" target="_blank">SAMS</A></FONT></STRONG>
            </P>
            <P>
              <STRONG><FONT size="5"><A href="file:///\\MyMachine\C\ASPNETKScontent.htm">ASP.Net Kick Start</A></FONT></STRONG>
            </P>
          </TD>
          <TD><IMG id="Img1" alt="45% Voted" src="file:///\\MyMachine\C\Image\Rating5.bmp"></TD>
          <TD><IMG id="Img2" onclick="window.navigate('\\\\MyMachine\\C\\ASPNETKSsampchap.htm')" height="175" width="146" alt="Preview" src="file:///\\MyMachine\C\ASPNETKS.bmp"></TD>
          <TD><FONT size="5">45% Voted</FONT></TD>
        </TR>
        <TR>
          <TD>
            <P>
              <STRONG><FONT size="5"><A href="file:///\\MyMachine\C\TYASPNET21Dcontent.htm" target="_blank">SAMS</A></FONT></STRONG>
            </P>
            <P>
              <STRONG><FONT size="5"><A href="file:///\\MyMachine\C\TYASPNET21Dcontent.htm">Teach Yourself ASP.Net in 21 Days</A></FONT></STRONG>
            </P>
          </TD>
          <TD><IMG id="Img3" alt="78% Voted" src="file:///\\MyMachine\C\Image\Rating5.bmp"></TD>
          <TD><IMG id="Img4" onclick="window.navigate('\\\\MyMachine\\C\\TYASPNET21Dsampchap.htm')" height="175" width="146" alt="Preview" src="file:///\\MyMachine\C\TYASPNET21D.bmp"></TD>
          <TD><FONT size="5">78% Voted</FONT></TD>
        </TR>
        </TABLE>
      </body>
    </html>
    I want to be able to change the data in the Access file and the changes will be reflected in the asp page. So if I add a book nfo to the DB file then that book will be added to the asp html output.

    Other users on the LAN will use this site, and have unrestricted access to the linked files. They can use the file protocol to access any file of my C drive even when ASP/IIS does not put out these files.

    Therefore, what ASP/HTML/DHTML/JScript/VBScript code accesses the DB file and presents its data in a html table?

    I could snip some code, but I want to understand every line that I write, starting at accessing the DB. Plus, I could use some ASP code lines for rendering the data of each column. Note that instead of showing the interger for the Rating, I want to show a picture e.g. Rating=5 should produce picture=image\Rating5.bmp and so on. (Rating ranges from 0-5 in the Access file.) I also want to convert the local file paths to network file paths, given that my computer has the name "MyMachine" and the C drive is shared as "C".

    PS
    I simple want to put the data in a table of a web page, and I could use any advice on how to do this but I only want to keep this in pure ASP. No .Net
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  2. #2
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    That would take a bit of coding crosswire. You gonna be doing this?

    Basically, you will have an ASP page, with the connection to the database. Retrieve the info from the database, manipulate it, storing the data into variables, loop through the data and use the Response.Write to output the html with the data.

    If the only problem you need is how to connect to a database from ASP page, there are a lot of articles online that would show you how.

    W3Schools shows you how to connect to database using ADO.
    http://www.w3schools.com/ado/default.asp

    They have some examples there that fits into what you're trying to do.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  3. #3
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Thank AA for the ADO link. It is very good
    That would take a bit of coding crosswire. You gonna be doing this?
    Yes, quite bored.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  4. #4
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    If you need any help along the way, let me know.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  5. #5
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Thanks to AA's help and links I did it

    HTML Code:
    <%@ Language=javascript %>
    <html>
      <head>
        <title>Books - Preview Page</title>
      </head>
      <body bgcolor="#ffccff" link="#000099" vlink="#000033">
        <TABLE id="Table1" cellSpacing="3" cellPadding="5" border="10" align="center">
    	<%
    	var	iNFields				=	7;
    	var	iIndexColTitle			=	0;
    	var	iIndexColPublisher		=	1;
    	var	iIndexColRating			=	2;
    	var	iIndexColPopularity		=	3;
    	var	iIndexColPicPath		=	4;
    	var	iIndexColPreviewPath	=	5;
    	var	iIndexColBookPath		=	6;
    
        var conn	=	Server.CreateObject("ADODB.Connection");
        conn.ConnectionString	=	"Provider=Microsoft.Jet.OLEDB.4.0; Password=; User ID=; Data Source=C:\\temp\\BookPreview\\BookInfo.mdb";
        conn.Open();
    	if(conn.State!=1)
    	{
    		Response.Write("No connection is opened!<br>");
    	}
    
    	var rs		=	Server.CreateObject("ADODB.recordset");
    	rs.Open("BooksInfo", conn);
    
    	var	MyMachine	=	"\\\\192.168.1.102";
    	var	f;
    	while(!rs.EOF)
    	{
    %>
        <TR>
          <TD>
            <P>
              <STRONG><FONT size="5"><A href="file:///<%=MyMachine%>\<%=rs.Fields(iIndexColBookPath).Value.replace(":","")%>" target="_blank"><%=rs.Fields(iIndexColPublisher)%></A></FONT></STRONG>
            </P>
            <P>
              <STRONG><FONT size="5"><A href="file:///<%=MyMachine%>\<%=rs.Fields(iIndexColBookPath).Value.replace(":","")%>"><%=rs.Fields(iIndexColTitle)%></A></FONT></STRONG>
            </P>
          </TD>
          <TD><IMG id="Img1" alt="<%=rs.Fields(iIndexColPopularity)%>% Voted" src="file:///<%=MyMachine%>\C\Image\Rating<%=rs.Fields(iIndexColRating)%>.bmp"></TD>
          <TD><IMG id="Img2" onclick="window.navigate('\\<%=MyMachine%>\\<%=rs.Fields(iIndexColPreviewPath).Value.replace(":","").replace("\\","\\\\")%>')" height="175" width="146" alt="Preview" src="file:///<%=MyMachine%>\<%=rs.Fields(iIndexColPicPath).Value.replace(":","")%>"></TD>
          <TD><FONT size="5"><%=rs.Fields(iIndexColPopularity)%>% Voted</FONT></TD>
        </TR>
    <%
    		rs.MoveNext();
    	}
    
    	rs.Close();
    	conn.Close();
    	%>
        </TABLE>
      </body>
    </html>
    I still have to organize the code and 'neat' it up, but it basicaly does what I want.

    I think I will try to do a pure javascript implementation using only client code. So I can run it off localhost when I turn off IIS.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  6. #6
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    And here is the javascipt .htm file that can run off my local hard disk not localhost

    HTML Code:
    <html>
    	<head>
    		<title>Books - Preview Page</title>
    	</head>
    	<body bgcolor="#ffccff" link="#000099" vlink="#000033">
    	<script language="javascript">
    	document.write(
    	"<TABLE id='Table1' cellSpacing='3' cellPadding='5' border='10' align='center'>"
    	);
    	var	iNFields				=	7;
    	var	iIndexColTitle			=	0;
    	var	iIndexColPublisher		=	1;
    	var	iIndexColRating			=	2;
    	var	iIndexColPopularity		=	3;
    	var	iIndexColPicPath		=	4;
    	var	iIndexColPreviewPath	=	5;
    	var	iIndexColBookPath		=	6;
    
        var conn	=	 new ActiveXObject("ADODB.Connection");
        conn.ConnectionString	=	"Provider=Microsoft.Jet.OLEDB.4.0; Password=; User ID=; Data Source=G:\\My Books\\___By Category\\BookInfo.mdb";
        conn.Open();
    	if(conn.State!=1)
    	{
    		alert("No connection is opened!<br>");
    	}
    
    	var rs		=	new ActiveXObject("ADODB.recordset");
    	rs.Open("SELECT * FROM BooksInfo ORDER BY PK ASC", conn);
    
    	var	MyMachine	=	"";
    	//alert("begin render table");
    	var	iid	=	0;
    	var	f;
    	while(!rs.EOF)
    	{
    		document.write(
    		"<TR>" +
    			"<TD>" +
    				//"<P><STRONG>Test Cell</STRONG></P>" +
    				"<P><STRONG><FONT size='5'><A href='file:///" + rs.Fields(iIndexColBookPath).Value + "' target='_blank'>" + rs.Fields(iIndexColPublisher) + "</A></FONT></STRONG></P>" +
    				"<P><STRONG><FONT size='5'><A href='file:///" + rs.Fields(iIndexColBookPath).Value + "'>" + rs.Fields(iIndexColTitle) + "</A></FONT></STRONG></P>" +
    		    "</TD>" +
    			"<TD><IMG id='Img" + (++iid) + "' alt='" + rs.Fields(iIndexColPopularity) + "% Voted' src='file:///" + "I:\\MSPress\\images\\review\\" + rs.Fields(iIndexColRating) + "stars.gif'></TD>" +
    			"<TD><IMG id='Img" + (++iid) + "' onclick='window.navigate(\"" + rs.Fields(iIndexColPreviewPath).Value.replace(/\\/g,"\\\\") + "\")' height='175' width='146' alt='Preview' src='file:///" + rs.Fields(iIndexColPicPath).Value + "'></TD>" +
    			//"<TD><IMG id='Img" + (++iid) + "' onclick='window.navigate(\"home\")' height='175' width='146' alt='Preview' src='file:///" + MyMachine + "\\" + rs.Fields(iIndexColPicPath).Value.replace(":","") + "'></TD>" +
    			"<TD><FONT size='5'>" + rs.Fields(iIndexColPopularity) + "% Voted</FONT></TD>" +
    		"</TR>"
    		);
    		rs.MoveNext();
    
    		//document.images.item("Img" + iid).onclick	=	OnClickTest;
    		
    		//alert("next");
    	}
    	rs.Close();
    	conn.Close();
    	document.write("</TABLE>");
    	
    	function OnClickTest()
    	{
    		alert("dfSD");
    	}
    	
    	/*
    	function replaceAll(strIn, strFind, strRepl)
    	{
    		while(true)
    		{
    			if(strIn.search(strFind) == -1)
    				return	strIn;
    			strIn	=	strIn.replace(strFind, strRepl);
    		}
    	}
    	*/
    	</script>
    	</body>
    </html>
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •