欢迎光临
我们一直在努力

用select语句读excel表-ASP教程,ASP应用

建站超值云服务器,限时71元/月

<%

—————————————————

function getmdbconnection( filename )

dim provider, dbpath

provider = "provider=microsoft.jet.oledb.4.0;"

dbpath = "data source=" & server.mappath(filename)

set getmdbconnection = getconnection( provider & dbpath )

end function

—————————————————

function getsecuredmdbconnection( filename, password )

dim provider, dbpath

provider = "provider=microsoft.jet.oledb.4.0;"

dbpath = "data source=" & server.mappath(filename)

set getsecuredmdbconnection = getconnection( provider & dbpath & ";jet oledb:database password=" & password )

end function

—————————————————

function getdbcconnection( filename )

dim driver, sourcetype, dbpath

driver = "driver={microsoft visual foxpro driver};"

sourcetype = "sourcetype=dbc;"

dbpath = "sourcedb=" & server.mappath( filename )

set getdbcconnection = getconnection( driver & sourcetype & dbpath )

end function

—————————————————

function getdbfconnection( directory )

dim driver, sourcetype, dbpath

driver = "driver={microsoft visual foxpro driver};"

sourcetype = "sourcetype=dbf;"

dbpath = "sourcedb=" & server.mappath( directory )

set getdbfconnection = getconnection( driver & sourcetype & dbpath )

end function

—————————————————

function getexcelconnection( filename )

dim driver, dbpath

driver = "driver={microsoft excel driver (*.xls)};"

dbpath = "dbq=" & server.mappath( filename )

set getexcelconnection = getconnection( driver & "readonly=0;" & dbpath )

end function

—————————————————

function gettextconnection( directory )

dim driver, dbpath

driver = "driver={microsoft text driver (*.txt; *.csv)};"

dbpath = "dbq=" & server.mappath( directory )

set gettextconnection = getconnection( driver & dbpath )

end function

—————————————————

function getsqlserverconnection( computer, userid, password, db )

dim params, conn

set getsqlserverconnection = nothing

params = "provider=sqloledb.1"

params = params & ";data source=" & computer

params = params & ";user id=" & userid

params = params & ";password=" & password

params = params & ";initial catalog=" & db

set conn = server.createobject("adodb.connection")

conn.open params

set getsqlserverconnection = conn

end function

—————————————————

function getmdbrecordset( filename, source )

set getmdbrecordset = getmdbrs( filename, source, 2, "" )

end function

—————————————————

function getmdbstaticrecordset( filename, source )

set getmdbstaticrecordset = getmdbrs( filename, source, 3, "" )

end function

—————————————————

function getsecuredmdbrecordset( filename, source, password )

set getsecuredmdbrecordset = getmdbrs( filename, source, 2, password )

end function

—————————————————

function getsecuredmdbstaticrecordset( filename, source, password )

set getsecuredmdbstaticrecordset = getmdbrs( filename, source, 3, password )

end function

—————————————————

function getdbfrecordset( directory, sql )

set getdbfrecordset = getotherrs( "dbf", directory, sql, 2 )

end function

—————————————————

function getdbfstaticrecordset( directory, sql )

set getdbfstaticrecordset = getotherrs( "dbf", directory, sql, 3 )

end function

—————————————————

function getdbcrecordset( filename, sql )

set getdbcrecordset = getotherrs( "dbc", filename, sql, 2 )

end function

—————————————————

function getdbcstaticrecordset( filename, sql )

set getdbcstaticrecordset = getotherrs( "dbc", filename, sql, 3 )

end function

—————————————————

function getexcelrecordset( filename, sql )

set getexcelrecordset = getotherrs( "excel", filename, sql, 2 )

end function

—————————————————

function getexcelstaticrecordset( filename, sql )

set getexcelstaticrecordset = getotherrs( "excel", filename, sql, 3 )

end function

—————————————————

function gettextrecordset( directory, sql )

set gettextrecordset = getotherrs( "text", directory, sql, 2 )

end function

—————————————————

function gettextstaticrecordset( directory, sql )

set gettextstaticrecordset = getotherrs( "text", directory, sql, 3 )

end function

—————————————————

function getsqlserverrecordset( conn, source )

dim rs

set rs = server.createobject("adodb.recordset")

rs.open source, conn, 2, 2

set getsqlserverrecordset = rs

end function

—————————————————

function getsqlserverstaticrecordset( conn, source )

dim rs

set rs = server.createobject("adodb.recordset")

rs.open source, conn, 3, 2

set getsqlserverstaticrecordset = rs

end function

—————————————————

function getconnection( param )

dim conn

on error resume next

set getconnection = nothing

set conn = server.createobject("adodb.connection")

if err.number <> 0 then exit function

conn.open param

if err.number <> 0 then exit function

set getconnection = conn

end function

—————————————————

function getmdbrs( filename, source, cursor, password )

dim conn, rs

on error resume next

set getmdbrs = nothing

if len(password) = 0 then

set conn = getmdbconnection( filename )

else

set conn = getsecuredmdbconnection( filename, password )

end if

if conn is nothing then exit function

set rs = server.createobject("adodb.recordset")

if err.number <> 0 then exit function

rs.open source, conn, cursor, 2

if err.number <> 0 then exit function

set getmdbrs = rs

end function

—————————————————

function getotherrs( datatype, path, sql, cursor )

dim conn, rs

on error resume next

set getotherrs = nothing

select case datatype

case "dbf"

set conn = getdbfconnection( path )

case "dbc"

set conn = getdbcconnection( path )

case "excel"

set conn = getexcelconnection( path )

case "text"

set conn = gettextconnection( path )

end select

if conn is nothing then exit function

set rs = server.createobject("adodb.recordset")

if err.number <> 0 then exit function

rs.open sql, conn, cursor, 2

if err.number <> 0 then exit function

set getotherrs = rs

end function

—————————————————

function getsqlserverrs( computer, userid, password, db, source, cursor )

dim conn, rs

on error resume next

set getsqlserverrs = nothing

set conn = getsqlserverconnection( computer, userid, password, db )

if conn is nothing then exit function

set rs = server.createobject("adodb.recordset")

if err.number <> 0 then exit function

rs.open source, conn, cursor, 2

if err.number <> 0 then exit function

set getsqlserverrs = rs

end function

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用select语句读excel表-ASP教程,ASP应用
分享到: 更多 (0)