Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel automated query snapshot

Status
Not open for further replies.

evilmousse

Programmer
Apr 15, 2003
85
0
0
US

I'm attempting to create my own customized outtoexcel funtion, to be run client-side by users of an intranet asp.net application.

Right now I'm trying to get an accurate recordcount from my ado recordset object, but it always fails due to my inability to get a non-forwardonly recordset.

I'll also need to be considering how to manage the sqlserver authentication securely, since this would
involve passing the client a connection string to draw it's own data. I could use advice to this end.

Moving on to the problem at hand, can someone tell me why I continue to get a forwardonly recordset no matter how many times i explicitly ask for a static one?

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<BODY>
<INPUT id=&quot;button1&quot; name=&quot;button1&quot; type=&quot;button&quot; value=&quot;Button&quot;>
<SCRIPT LANGUAGE=&quot;VBScript&quot;>

sub button1_onclick()

'prepare excel
dim app
set app = createobject(&quot;Excel.Application&quot;)
app.Visible = true
dim wb
set wb = app.workbooks.add

'prepare ADO connection
Dim objConn, objRS
Set objConn = CreateObject(&quot;ADODB.Connection&quot;)
Set objRS = CreateObject(&quot;ADODB.Recordset&quot;)
With objConn
.Provider = &quot;sqloledb&quot;
.ConnectionString = &quot;CENSORED&quot; - right now a loalmachine with integrated sec
.Open
End With

'fill an array with a query
dim arr()
objrs.CursorType = adOpenStatic
objRS.Open &quot;Select top 20 * from loan_info&quot;, objConn, adOpenStatic
dim iii
iii = 999

'If objRS.Supports(adBookmark) = True Then
' iii = objrs.RecordCount
'end if
dim i, ii, j, jj
ii = 19
jj = objRS.Fields.count
i=0
redim arr(20,jj-1)

'fill title row
j = -1
for each x in objRS.fields
if j < jj then
j=j+1
arr(0,j) = x.name
end if
next

'fill data rows
do until objRS.EOF or i > ii
j = -1
i = i+1
for each x in objRS.fields
if j < jj then
j=j+1
arr(i,j) = objRS.CursorType
'arr(i,j) = x.value
end if
next
objRS.moveNext
loop

objRS.close
objConn.close
Set objRS = Nothing
Set objConn = Nothing

'assign the array to the excel sheet
dim rng
set rng = wb.Activesheet.Range(&quot;A1&quot;).Resize(21,jj)
rng.value = arr

'set freezepane, autoresize columns, & set title bgcolor to yellow
wb.Activesheet.Range(&quot;B2&quot;).Select
app.ActiveWindow.FreezePanes = True
wb.Activesheet.Cells.Columns.AutoFit
wb.sheets(&quot;sheet1&quot;).Rows(&quot;1:1&quot;).Interior.ColorIndex = 6

' Give the user control of Excel
app.UserControl = true

end sub
</SCRIPT>
</BODY>
</HTML>
 

Well, I found my problem.
Values I presumed were already of an appropriate
scope were not. Such as &quot;adOpenStatic&quot;. Turns
out vbscript was just creating them and defaulting
to zero. So now I have some statements above
the prior posted code like &quot;adOpenStatic = 3&quot;,
and all is well.

grift:
Tell me what you mean by turning it into an asp
please. I didn't like the options demo'd on the
page you posted.

I've now got just about all I need, my only critical outstanding issue is getting the proper validation to happen on the input argument textboxes. I'll
probably post that question once I can articulate it.
(these textboxes are already validating under another
context, but fail to on this new buttonclick)

-g
 
my suggestion was that for the parts that you needed to provide that require a DB connection, you could have an ASP page that would do all of that on the server side and then send the page as you have, but with the data included rather than the connection string to the DB.

What did you not like about the demos on the site ?
 
evilmousse, to avoid your scope problem, allways use the
Code:
 Option Explicit
instruction.

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top