Hi,
I am inserting into a database by looping over some excel spreadsheets and then inserting the results into a 2d array using getrows, everyhthing is good to here,
I store this in a session variable which I then insert into the database.
problem is in my loop the session variable only gets the first sheets data...
I have tried to redim my session array which it does not like, I have also tried converting to a local array and then reinstating that array as my session array.
Sorry about the big chunk of code but I have marked where my session var is and hopefully someone has tried to do something like this before.
' -- loop over the sheets
For Each Sheet In colSheets
' -- Create a Recordset Object
Dim Conn
Dim Rs
Dim SQL
'Conn.Open
Set Conn = Server.CreateObject("ADODB.Connection"
Set Rs = Server.CreateObject("ADODB.Recordset"
Conn.Open "DefaultDir=" & path & File & ";Driver={Microsoft Excel Driver (*.xls)};"
Response.write "<strong>" & Sheet.Name & "</strong><p></p>"
SQL = "SELECT * FROM [" & Sheet.Name & "$] " &_
" Where QcNum IS NOT Null "
rs.Open SQL, Conn, 1,3
alldata = rs.GetRows
' -- Set a session variable in order to use the array later to import
Session("ImpData" = alldata <--------------THATS THE ONE I NEED TO ADD TO
' -- Output the excel data so the user can see the info is correct
response.write "<table border='1'><tr>" & vbcrlf
'Put Headings On The Table of Field Names
for each column in rs.fields
response.write "<td><b>" & column.name & "</B></TD>" & vbcrlf
next
response.write "</tr>" & vbcrlf
' grab all the records
numcols=ubound(alldata,1)
numrows=ubound(alldata,2)
FOR rowcounter= 0 TO numrows
response.write "<tr>" & vbcrlf
FOR colcounter=0 to numcols
thisfield=alldata(colcounter,rowcounter)
if isnull(thisfield) then
thisfield=shownull
end if
if trim(thisfield)="" then
thisfield=showblank
end if
response.write "<td valign=top>"
response.write thisfield
response.write "</td>" & vbcrlf
NEXT
response.write "</tr>" & vbcrlf
NEXT
response.write "</table><p></p>"
next
%>
<hr>
<form action="import.asp" method="post"><input type="submit" name="btn" value="Import"></form>
</body>
</html>
<% End If %>
<% If request.form("btn" = "Import" then
Dim ImpConn
Dim ImpRs
Set ImpConn = Server.CreateObject("ADODB.Connection"
Set ImpRs = Server.CreateObject("ADODB.Recordset"
ImpConn.Open Application("GlobalQCSQL_ConnectionString"
ImpRs.Open "Tests", ImpConn, 0,3
' -- The actual importing gets done
For i = 0 to ubound(Session("ImpData",2)
ImpRs.AddNew
ImpRs("QcNum" = Session("ImpData"(0,i)
ImpRs("Date" = Session("ImpData"(1,i)
ImpRs("Time" = Session("ImpData"(2,i)
ImpRs("Measurement1" = Session("ImpData"(3,i)
ImpRs("Measurement2" = Session("ImpData"(4,i)
ImpRs("YesNo" = Session("ImpData"(5,i)
ImpRs("MachineID" = Session("ImpData"(6,i)
ImpRs("Cavity" = Session("ImpData"(7,i)
ImpRs("Gauge" = Session("ImpData"(8,i)
ImpRs("Comment" = Session("ImpData"(9,i)
ImpRs.Update
Next
Response.write "Bingo, Your import went well take the week off with pay"
%>
I am inserting into a database by looping over some excel spreadsheets and then inserting the results into a 2d array using getrows, everyhthing is good to here,
I store this in a session variable which I then insert into the database.
problem is in my loop the session variable only gets the first sheets data...
I have tried to redim my session array which it does not like, I have also tried converting to a local array and then reinstating that array as my session array.
Sorry about the big chunk of code but I have marked where my session var is and hopefully someone has tried to do something like this before.
' -- loop over the sheets
For Each Sheet In colSheets
' -- Create a Recordset Object
Dim Conn
Dim Rs
Dim SQL
'Conn.Open
Set Conn = Server.CreateObject("ADODB.Connection"
Set Rs = Server.CreateObject("ADODB.Recordset"
Conn.Open "DefaultDir=" & path & File & ";Driver={Microsoft Excel Driver (*.xls)};"
Response.write "<strong>" & Sheet.Name & "</strong><p></p>"
SQL = "SELECT * FROM [" & Sheet.Name & "$] " &_
" Where QcNum IS NOT Null "
rs.Open SQL, Conn, 1,3
alldata = rs.GetRows
' -- Set a session variable in order to use the array later to import
Session("ImpData" = alldata <--------------THATS THE ONE I NEED TO ADD TO
' -- Output the excel data so the user can see the info is correct
response.write "<table border='1'><tr>" & vbcrlf
'Put Headings On The Table of Field Names
for each column in rs.fields
response.write "<td><b>" & column.name & "</B></TD>" & vbcrlf
next
response.write "</tr>" & vbcrlf
' grab all the records
numcols=ubound(alldata,1)
numrows=ubound(alldata,2)
FOR rowcounter= 0 TO numrows
response.write "<tr>" & vbcrlf
FOR colcounter=0 to numcols
thisfield=alldata(colcounter,rowcounter)
if isnull(thisfield) then
thisfield=shownull
end if
if trim(thisfield)="" then
thisfield=showblank
end if
response.write "<td valign=top>"
response.write thisfield
response.write "</td>" & vbcrlf
NEXT
response.write "</tr>" & vbcrlf
NEXT
response.write "</table><p></p>"
next
%>
<hr>
<form action="import.asp" method="post"><input type="submit" name="btn" value="Import"></form>
</body>
</html>
<% End If %>
<% If request.form("btn" = "Import" then
Dim ImpConn
Dim ImpRs
Set ImpConn = Server.CreateObject("ADODB.Connection"
Set ImpRs = Server.CreateObject("ADODB.Recordset"
ImpConn.Open Application("GlobalQCSQL_ConnectionString"
ImpRs.Open "Tests", ImpConn, 0,3
' -- The actual importing gets done
For i = 0 to ubound(Session("ImpData",2)
ImpRs.AddNew
ImpRs("QcNum" = Session("ImpData"(0,i)
ImpRs("Date" = Session("ImpData"(1,i)
ImpRs("Time" = Session("ImpData"(2,i)
ImpRs("Measurement1" = Session("ImpData"(3,i)
ImpRs("Measurement2" = Session("ImpData"(4,i)
ImpRs("YesNo" = Session("ImpData"(5,i)
ImpRs("MachineID" = Session("ImpData"(6,i)
ImpRs("Cavity" = Session("ImpData"(7,i)
ImpRs("Gauge" = Session("ImpData"(8,i)
ImpRs("Comment" = Session("ImpData"(9,i)
ImpRs.Update
Next
Response.write "Bingo, Your import went well take the week off with pay"
%>