久久久精品2019免费观看_亚洲国产精品成人久久久_69国产成人综合久久精品91_国产精品久久精品视

asp上傳excle文件并導(dǎo)入到access數(shù)據(jù)庫

<%

function FSOFileDel(filename)

Dim objFSO,objCountFile,FiletempData

On Error Resume Next

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Set objCountFile =objFSO.DeleteFile(Server.MapPath(filename),true)

objCountFile.Close

Set objCountFile=Nothing

Set objFSO = Nothing

End Function








dim action,files

action=trim(request("action"))

files=trim(request("files"))

select case action

case "add"

call add(files)

case else

call default()

end select        

%>



<%sub default()%>

<form action="?action=add" method="post" id="form1" name="form1">

<table border="0" cellspacing="0" cellpadding="0">

<tr class="title2">

<td colspan="2">批量上傳</td>

</tr>

<tr>

<td>1.上傳Excle文件&nbsp;</td>

<td><input name="files" type="hidden" id="files" />

<iframe frameborder="0" scrolling="no" height="25" width="400" src="upload.asp?action=add"></iframe>&nbsp;</td>

</tr>

<tr>

<td>2.點(diǎn)擊"開始上傳"&nbsp;</td>

<td>  <label>

<input type="submit" name="button" id="button" value="開始上傳" />

</label>&nbsp;</td>

</tr>

</table>







</form>

<%end sub%>

<%

sub add(files)

dim FileName



if files="" then ClientAlert"請先上傳Excle文件","?"



FileName="../upload/file/"&files  '取得文件路徑

Dim connEX

set connEX=CreateObject("ADODB.connection")

connEX.Open "Driver={Microsoft Excel Driver (*.xls)};" & _

"DriverId=790;" & _

"Dbq=" & server.mappath(""&FileName&"") & ";" & _

"DefaultDir=G:" 



set rs=createobject("ADODB.recordset")

rs.Open "Select * From [Sheet1$]",connEX, 2, 2

if rs.eof then

response.write "Excel表中無紀(jì)錄"

else

'  set connDB = Server.CreateObject("ADODB.Connection")

'  DBPath = Server.MapPath("excel.mdb")

'  'RESPONSE.WRITE DBpath

'  connDB.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath

Set RsDB = Server.CreateObject("ADODB.Recordset")

SqlDB="Select * from product"

RsDB.open sqlDB,conn,1,3

do while not  rs.eof '利用循環(huán)讀出數(shù)據(jù)

RsDB.addnew

RsDB("ProName")=rs(0)

RsDB("ProClassId")=rs(1)

RsDB("ProPics")=rs(2)

RsDB("ProPic")=rs(3)

RsDB("ProFeaturesCn")=rs(4)

RsDB("IsNew")=rs(5)

RsDB("IsHot")=rs(6)

RsDB("Taxis")=rs(7)

Rs.update

RsDB.movenext

rs.movenext

loop

'response.redirect FileName

end if

RsDB.movefirst

if RsDB.eof then

response.write "數(shù)據(jù)庫中無記錄"

end if

rs.close

set rs=nothing

set connEX=nothing



Call FSOFileDel("../upload/file/"&files)'導(dǎo)入成功后及時(shí)刪除上傳文件.



ClientAlert"導(dǎo)入成功,點(diǎn)確定繼續(xù)。","?"

end sub
 

%>

未經(jīng)允許不得轉(zhuǎn)載:445IT之家 » asp上傳excle文件并導(dǎo)入到access數(shù)據(jù)庫

贊 (0) 打賞

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

微信掃一掃打賞