asp将Excel导入Access问题
<%dim conn
dim conn2
curDir = Server.MapPath("../Data/EMGWebMapCommision.mdb")
set conn=CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & curDir
set conn2=CreateObject("ADODB.Connection")
conn2.Open "Driver={Microsoft Excel Driver (*.xls)};ReadOnly=0;DBQ=" & Server.MapPath("../emapgo.xls")
sql = "SELECT * FROM [Sheet1$]"
set rs = conn2.execute(sql)
while not rs.eof
sql = "insert into MapCommision([HardWareNo],[MapCode],[UserName],[UpdateCode]) values('"& fixsql(rs(0)) &"','"& fixsql(rs(1)) &"','"& fixsql(rs(2)) &"','"& fixsql(rs(3)) &"')"
conn.execute(sql)
rs.movenext
wend
conn.close
set conn = nothing
conn2.close
set conn2 = nothing
function fixsql(str)
dim newstr
newstr = str
if isnull(newstr) then
newstr = ""
else
newstr = replace(newstr,"'","''")
end if
fixsql = newstr
end function
Response.Write("<script language='javascript'>alert('恭喜您,添加成功!');window.location.href='Admin_info.asp';</script>")
%>
错误类型:
Microsoft JET Database Engine (0x80004005)
字段 'MapCommision.UpdateCode' 不能是零长度的字符串。
/asp/WebMap/Admin/Excel.asp, 第 16 行
因为在实际过程中肯定要有空字段的
[此贴子已经被作者于2006-9-8 9:28:10编辑过]