Database tables to array

Results 1 to 2 of 2

Thread: Database tables to array

  1. #1
    Join Date
    Dec 1969

    Default Database tables to array

    Hi<BR><BR>I&#039;m largely a &#039;front-end&#039; developer, I&#039;m afraid, with only limited ASP and Perl experience, so apologies if the following problem is just TOO easy to solve! Also, I&#039;m particularly poor when it comes to arrays, which is the problem I&#039;ve got here, I think. If anyone can help, I&#039;d really appreciate it...<BR><BR>Right...<BR><BR>The following code opens up a connection to a database and lists the tables in that database:<BR><BR>&#060;form&#062;<BR>&#060;select NAME="selectMonth" onChange="goto_URL(this.form.selectName)"&#062;<BR ><BR>&#060;% <BR><BR>ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" <BR>ConnStr = ConnStr & Server.MapPath ("dbase/2001to2002.mdb") <BR><BR>set adoxConn = Server.CreateObject("ADOX.Catalog") <BR>set adodbConn = Server.CreateObject("ADODB.Connection") <BR> ConnStr <BR>adoxConn.activeConnection = adodbConn<BR><BR>Set MonthsUnavailable = adoxConn.Tables<BR><BR>for each table in MonthsUnavailable <BR>if table.type="TABLE" then <BR>response.write "&#060;option value=output_name.asp?" & & "&#062;" & & "&#060;/option&#062;"<BR>end if <BR>next<BR><BR><BR>adodbConn.close: set adodbConn = nothing <BR>set adoxConn = nothing <BR>%&#062;<BR><BR>&#060;/select&#062;<BR>&#060;/form&#062;<BR><BR><BR>Currently, these tables are named "January" and "February".<BR><BR>Now, I know how create tables (in an Access 2000 database) in ASP, and will be offering people another selectbox from which they can choose to &#039;create&#039; further months. However, once a month/table has been created, and appears in the selectbox generated by the code above, I of course DON&#039;T want it to appear in the second selectbox, from which people can select to create the new month/table. <BR><BR>I&#039;ve assumed that the easiest way to achieve this would be by comparing two arrays, one with all 12 months, the other containing just the months produced by the code above. The following code would achieve this, if only I could get the list of existing tables produced above into an array...<BR><BR>&#060;%<BR>MonthsAvailable = "January,February,and,so,on,to,December"<BR>Unavai lableMonths = "?????????????????????"<BR><BR>ARR1 = split(MonthsAvailable,",")<BR>ARR2 = split(UnavailableMonths,",")<BR><BR>strOutput = "("<BR>for i = 0 to ubound(ARR1)<BR>found = "false"<BR>for j = 0 to ubound(ARR2)<BR>if (ARR1(i) = ARR2(j)) then<BR>found = "true"<BR>exit for<BR>end if<BR>next<BR>if found ="false" then<BR>strOutput=strOutput & ARR1(i) & ","<BR>ARR1temp = ARR1(i)<BR>end if<BR>next<BR><BR>strOutput = Left(strOutput, Len(strOutput)-1)<BR>strOutput = strOutput & ")"<BR><BR>Response.write("<BR>" & strOutput & "<BR>")<BR>%&#062;<BR><BR>But I don&#039;t know how to do this! I keep getting mismatches and all manner of errors, and can&#039;t find any info on the adoxConn.tables set anywhere. Can anyone help here? Or, alternatively, if this is a silly way of doing it, suggest an alternative?<BR><BR>Once again, apologies if the answer is simple! I&#039;m still finding my way here...<BR><BR>Thanks<BR>Terry <BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Database tables to array

    I&#039;m not sure how you get the table names in Access, but probably the quickest way of finding out if a table exists in an array is actually not to use and array, use a string instead<BR><BR>i.e.<BR>MonthsAvail = ",jan,feb,etc..."<BR>If InStr(MonthsAvail,",feb,")&#062;0 then<BR> &#039; feb is avail..<BR>End if<BR><BR>This doesn&#039;t involve any arrays or looping which takes processor, to turn an array to a string you can use .join

Posting Permissions

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