我在调用时传了两个参数,一个是sql="select * from tbl_user",一个是数据库连接的,conn= "Provider=SQLOLEDB.1;Persist Security Info=True; User ID=sa;Password=..; Data Source=..;Initial Catalog=.." 传值是总提示类型不符,请多指教
...全文
1384打赏收藏
我在vb里面将导出数据到excel写入了dll文件,请问在asp中怎么调用
我在调用时传了两个参数,一个是sql="select * from tbl_user",一个是数据库连接的,conn= "Provider=SQLOLEDB.1;Persist Security Info=True; User ID=sa;Password=..; Data Source=..;Initial Catalog=.." 传值是总提示类型不符,请多指教
Public Function ExporToExcel(str1 as string,str2 as string)
'ExporToExcel = False
'On Error GoTo ErrHandler
Dim Rs_Data As New ADODB.Recordset
Dim Irowcount As Integer
Dim Icolcount As Integer
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQuery As Excel.QueryTable
' Dim Conn As New Connection
' Set Conn = New ADODB.Connection
' Conn.Open str1
With Rs_Data
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = str1
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Source = str2
.Open
End With
With Rs_Data
If .RecordCount < 1 Then
MsgBox ("沒有數據記錄!")
Exit Function
End If
Irowcount = .RecordCount '記錄總數
Icolcount = .Fields.Count '字段總數
End With
Set xlApp = CreateObject("Excel.Application")
Set xlBook = Nothing
Set xlSheet = Nothing
Set xlBook = xlApp.Workbooks().Add
Set xlSheet = xlBook.Worksheets("sheet1")
xlApp.Visible = True
Set xlQuery = xlSheet.QueryTables.Add(Rs_Data, xlSheet.Range("a1"))