Here's a toughy.....any thoughts? (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


Guest -> Here's a toughy.....any thoughts? (3/14/2001 16:18:00)

Our company creates a new database each month with two tables in each holding all the order transactions for that month.

I have a form that looks something like this:

<form method="POST" name="myform">
<P ALIGN="Center"> Order: <input type="text" size="12" name="Order" value = ""> </p>
<P ALIGN="Center"> <br><center>
<input type="submit" value="Billing">
<select name="MONTH" size="1">
<option selected value="0">January</option>
<option value="1">Febuary</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select>
<select name="YEAR" size="1">
<option value="1999">1999</option>
<option value="2000">2000</option>
<option selected value="2001">2001</option>
</select>
</center></p>
</form>

We are moving from a CGI based web to ASP. We want our customers to be able to put in an order number, month and date and return all the orders for that month. In CGI, we had yet another database which contained a table mapping the month values above (0,1,2,etc) and year values to the physical address of the DB and the table within that database. How do I do this is ASP? The field names for each table in each database are the same yet each table is named different in each database (based on the month). All the database system names are mapped in the Global.asa file and are verifeid.

Seems like a need some work on the fp_sQry= and fp_sDataConn= lines using some sort of strings.

I could create a separte query page for each month....but that's an enormous amount of work.....






Elecia -> RE: Here's a toughy.....any thoughts? (3/15/2001 20:57:00)

I would suggest that you set up a database and table just like you had before with the path to the db and the name of the table. Run your query to get this info and then using Dimmed parameters insert these values into your connection string for the query that will display the order info to your clients.

Something along these lines
Dim MyPath
MyPath = rs.fields.getvalue("MyFieldNameWhereThePathIsStored")
DIM myCNN

myCNN ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyPath

Then do the same type of thing in your SQL string for the From statement.

EE





Guest -> RE: Here's a toughy.....any thoughts? (3/15/2001 23:39:00)

ASP a realitivly new to me and as I'm sure your response would make perfect sense to a more experienced person...."Dim" is a new concept to me.....

If I give some names...can you be more decriptive in my tasks??

For simplicity...let's say three databases are located on the local machine in c:\databases\

Database1 has a table named MAPS with 4 columns:
MONTH (using 1,2,3...etc as described above)
YEAR (1999, 2000, etc)
LOCATION (i.e. c:\databases\DEC00.gdb)
TABLE (identifies table in LOCATION)

DEC00 and JAN01 are the monthly generated databases and contain tables DECOrders and JANOrders respectfully.....each table has the same exact fields, of which I am quering for ORDERS

Thus, MAPS would have an entry of 12, 2000, c:\database\DEC00.gdb, DECOrders and likewise for JAN01

How do I apply this to your idea above and what would the SQL statement look like....

Many thanks in advance for this!





Elecia -> RE: Here's a toughy.....any thoughts? (3/16/2001 20:13:00)

Sorry I'm not ignoring you I've been a little busy. I do a better example and post it this afternoon.
EE




Guest -> RE: Here's a toughy.....any thoughts? (3/16/2001 20:51:00)

I appreicate your efforts and thank you in advance.

Of note....I am placing the databases on the my local machine for simplicity, but in reality they are on network servers separte from the web server...so ODBC/OLE connections would be necessary. Don't think this would make too much of a difference, but mentioned it just in case.





Elecia -> RE: Here's a toughy.....any thoughts? (3/16/2001 20:38:00)

OK here is the sample. I use the form that you had posted in the sample. I take the values of month and year selected by the client and used them to query a database I created. The database contains a table called PathandTable. Within PathandTable there are 4 columns Path (a text field that contains the actual path to another database), Table (a text field that contains the name of the table that I want to query),Month (an int field) and Year (an int field).
I pass the month and year the client selects to the PathandTable table. From the recordset that is returned I grab the value of Path and Table and assign them to variables. I use those variables to execute a second query which returns in the case of this sample a list of firstnames and writes them out to the page. All you need to do is change the data source for the first query and point it to the database that you are using to track your order databases with and then change the table name in the first Select statement from PathandTable to the name of the table in your database.
Hope this helps
EE
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
</HEAD>
<BODY>

<%'This if statement keeps the queries from running before the client has selected a month and year.
<%If Request("Month")= "" Then%>

<form method="POST" name="myform">
<P ALIGN="Center"> Order: <input type="text" size="12" name="Order" value = ""> </p>
<P ALIGN="Center"> <br><center>
<input type="submit" value="Billing" action="asp page2.asp">
<select name="MONTH" size="1">
<option selected value="0">January</option>
<option value="1">Febuary</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select>
<select name="YEAR" size="1">
<option value="1999">1999</option>
<option value="2000">2000</option>
<option selected value="2001">2001</option>
</select>
</center></p>
</form>


<%Else

Dim objConn,myMonth,myYear,WhereClause
myMonth = Request("Month")
myYear = Request("Year")
myMonth = cint(myMonth)
myYear = cint(myYear)
WhereClause = "Where"&" "& "PathandTable.Month=" &" "& mymonth & " " & "and PathandTable.Year=" & " "& myYear
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Documents and Settings\Administrator\Desktop\Mine\amsample.mdb;" 'Replace the data source I have here with the path to your database where the table and path names are stored.
objConn.Open
Dim RS
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "SELECT * FROM PathandTable " & WhereClause,objConn,adOpenStatic,adLockOptimistic
%>
<%
Dim rsPath,rsTable
'These are the variables that you will use in
'the query to retrieve the list of orders for the month and yr the client has specified
rsPath = Trim(rs.Fields("Path").value)
rsTable = Trim(rs.Fields("Table").value)
rs.Close
rsPath = cstr(rsPath)
rsTable = cstr(rsTable)
set rs = nothing
%>
<%Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
'the rsPath variable is used here to set your path to the database
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & rsPath & ";"
Conn.Open

Dim RSorder
Set RSorder = Server.CreateObject("ADODB.Recordset")
'the rsTable variable is used here to specify the Table you want to query
RSorder.Open "SELECT * FROM " & rsTable, Conn,adOpenStatic,adLockOptimistic%>
<table>
<%Do until RSorder.EOF%>
<tr>
<td><%=RSorder.Fields("AR_FirstName").value%></td>
<%RSorder.MoveNext
Loop
RSorder.Close
set rsorder= nothing
End if%>
</BODY>
</HTML>

[This message has been edited by Elecia (edited 03-16-2001).]





Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875