ASP 如何批量提交多条数据到数据库
2个回答
展开全部
Dim cn,oConn,connstr
'打开XLS.
Set cn=Server.CreateObject("ADODB.Connection")
cn.Provider="Microsoft.Jet.OLEDB.4.0 "
cn.ConnectionString = "Data Source= " & Server.MapPath( "data.xls ") & "; " & _
"Extended Properties=Excel "
'打开MDB.
Set oConn=Server.CreateObject("ADODB.Connection")
dd="../database/ty.mdb"
strProvider="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath (""&dd&"")
oConn.open strProvider
'读取数据.
set rsRead=server.CreateObject( "ADODB.Recordset ")
rsRead.Open "select * from [Sheet1$] ",cn,2,3
do until rsRead.EOF
'写入数据库.
oConn.Execute( "Insert into Student(Stuid,Sname,Ssex,Sxibie,Sclass)Values( ' "& rsRead.Fields( "Stuid ")& " ',' "& rsRead.Fields( "Sname ")& " ',' "& rsRead.Fields( "Ssex ")& " ',' "& rsRead.Fields( "Sxibie ")& " ', ' " &rsRead.Fields( "Sclass ") & " ') " )
rsRead.MoveNext
loop
'打开XLS.
Set cn=Server.CreateObject("ADODB.Connection")
cn.Provider="Microsoft.Jet.OLEDB.4.0 "
cn.ConnectionString = "Data Source= " & Server.MapPath( "data.xls ") & "; " & _
"Extended Properties=Excel "
'打开MDB.
Set oConn=Server.CreateObject("ADODB.Connection")
dd="../database/ty.mdb"
strProvider="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath (""&dd&"")
oConn.open strProvider
'读取数据.
set rsRead=server.CreateObject( "ADODB.Recordset ")
rsRead.Open "select * from [Sheet1$] ",cn,2,3
do until rsRead.EOF
'写入数据库.
oConn.Execute( "Insert into Student(Stuid,Sname,Ssex,Sxibie,Sclass)Values( ' "& rsRead.Fields( "Stuid ")& " ',' "& rsRead.Fields( "Sname ")& " ',' "& rsRead.Fields( "Ssex ")& " ',' "& rsRead.Fields( "Sxibie ")& " ', ' " &rsRead.Fields( "Sclass ") & " ') " )
rsRead.MoveNext
loop
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询