Drew Wutka
DWUTKA at Marlow.com
Fri Dec 7 17:39:59 CST 2007
http://www.marlow.com/ASPDataClassBuilder.zip The above file is a VB .exe that will immensely help with putting a database on the web using ASP. Let's go over using it. When you start the application, it will have 4 boxes at the bottom. Click the command button '...' next to the database path box. Find and open a database of your choice. If this is a secured database, select the workgroup and enter a UserName/Password. The left listbox should automatically populate once it can connect to the database (so if it's not a secured database, once you select a database). By default, it populates with the tables in the database. There's radio buttons above the list to switch between tables and queries. Select a table from the list (by clicking on it), and the right listbox populates with the fields of that table. Select the ID field of that table, by clicking on it. (The ID Field: textbox will populate with the field you selected). In the Single Class Name, type in the name of the class you want to create. By default, the 'Colleciton Class' populates with the single name, and adds an s, but you can change it to whatever you want. So, for an example, I created a little database with tblPeople. Fields PersonID, FirstName, LastName. I selected PersonID as the ID field. I then named the single class Person, and the Collection Class People. Click the Create DBConnect button. This puts the DBConnect code into your clipboard. Open a blank notepad session and paste the DBConnect function there. Do the same for the Single Class and Collection Class. Now, there are several ways to use these classes. The best way from an efficiency standpoint is to save each class (and the DBConnect function) as individual files. Then 'include' them in your web pages. I found a quirk with that, though. I use Microsoft Script Editor...which has intellisense. With the pages included, I don't get any prompts when writing the code. If the code is directly in the page, then I get intellisense prompts while coding the rest of the page. But from a system sense, having your classes in their one single files, allows you to make changes to those classes without having to change all affected pages. So, let's make a test page: <!-- #include virtual = "dbconnect.asp" --> <!-- #include virtual = "dbconnect.asp" --> <!-- #include virtual = "dbconnect.asp" --> <html> <head> <title>AccessD Test Page</title> </head> <body> <% dim i dim pr dim pl set pr=New Person set pl=New People for i=1 to pl.PersonCount set pr=pl.PersonInfo(i)%> <%=pr.LastName & ", " & pr.FirstName%><br> <%next%> <% set pr=nothing set pl=nothing %> </body> </html> Whalla, we now have a web page that displays the list of names we put into out tblPeople table. Pretty short page too, and since we are using classes in ASP, the code is much more 'readable'. Note, the .exe I put in the link above is mine, if anyone wants the VB source to it, email me off list. Every month or so I wipe out the extraneous files on our website, so that file will not be there in a month or so. Next email will create a more complex (and more useful) web page. Drew