ASP里,将Excel导入到Access数据库 10
用ASP编的一个网站,数据库是Access,数据库名称是atest,里面有个表格user,user表格有user和password两个字段现要将Excel表格(名称是te...
用ASP编的一个网站,数据库是Access,数据库名称是atest,里面有个表格user,user表格有user和password两个字段现要将Excel表格(名称是test.xls)的数据导入到atest数据库的user表中,怎么实现?高手支招
展开
2个回答
展开全部
下面连接到test.xls表sheet1$ '表后面要加个$的,一定要加这个符号
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Excel Driver (*.xls)};ReadOnly=0;DBQ=" & Server.MapPath("test.xls")
SQL1="select * from [sheet1$]"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open SQL1, conn, 3, 3
'下面连接到atest.mdb表user
curDir = Server.MapPath("atest.mdb")
Set conn1 = Server.CreateObject("ADODB.Connection")
conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & curDir
Set rs1 = Server.CreateObject("ADODB.Recordset")
Set rs1.ActiveConnection = conn1
rs1.Source = "select * from user"
rs1.CursorType = 3 ' adOpenKeyset
rs1.LockType = 3 'adLockOptimistic
rs1.Open
Do While Not rs.Eof
rs1.AddNew
rs1(0)=j
for i=0 to rs.Fields.Count-1
rs1(i)=Trim(rs(i))
Next
rs1.Update
rs.MoveNext
j=j+1
Loop
rs.Close
rs1.Close
conn.Close
conn1.Close
Set rs=nothing
Set conn=nothing
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Excel Driver (*.xls)};ReadOnly=0;DBQ=" & Server.MapPath("test.xls")
SQL1="select * from [sheet1$]"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open SQL1, conn, 3, 3
'下面连接到atest.mdb表user
curDir = Server.MapPath("atest.mdb")
Set conn1 = Server.CreateObject("ADODB.Connection")
conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & curDir
Set rs1 = Server.CreateObject("ADODB.Recordset")
Set rs1.ActiveConnection = conn1
rs1.Source = "select * from user"
rs1.CursorType = 3 ' adOpenKeyset
rs1.LockType = 3 'adLockOptimistic
rs1.Open
Do While Not rs.Eof
rs1.AddNew
rs1(0)=j
for i=0 to rs.Fields.Count-1
rs1(i)=Trim(rs(i))
Next
rs1.Update
rs.MoveNext
j=j+1
Loop
rs.Close
rs1.Close
conn.Close
conn1.Close
Set rs=nothing
Set conn=nothing
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询