Jeg har fundet nedenstående som dog ikke helt virker.
Jeg har en excelfil hvor der står:
Holdnr Navn Virksomhed
I databasen er der følgende felter
ID (autonr) Holdnr Navn Virksomhed
1. hvordan får jeg ID udfyldt? Skal det være med? Det er jo access autonummerering
2. Det eneste der sker når jeg kører det er at der står :
ID Holdnr Navn Virksomhed F5
På skærmen. Hvor kommer F5 fra og hvorfor sker der ikke mere?
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
'DECLARE THE ACCESS DATABASE CONNECTION
Dim rsAdd
Dim rsAdd_numRows
Set cn = Server.CreateObject("ADODB.Connection")
cn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\Team-Emilie\stafet\stafet.mdb"
set rsAdd = Server.CreateObject("ADODB.Recordset")
rsAdd.ActiveConnection = cn
rsAdd.Source = "SELECT * FROM Hold"
rsAdd.CursorLocation = 2
rsAdd.LockType = 3
rsAdd.Open()
rsAdd_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="
http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>IMPORT EXCEL FILE IN ACCESS DATABASE</title>
</head>
<body>
<%
Dim objConn, objRS, strSQL
Dim xIndex
'DECLARE THE EXCEL WORKSHEET CONNECTION
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=NO; "&_
"Excel 8.0; DBQ=" & Server.MapPath("Holdnumre.xls") & "; "
'SET QUERY TO SELECT THE DATA CELLS FROM THE EXCEL WORKSHEET
'THIS CAN BE DONE IN VARIOUS DIFFERENT WAYS, BUT THIS WORKED
'FOR MY PURPOSE
strSQL = "SELECT * FROM A1:Q10000"
'EXECUTE THE QUERY TO THE EXCEL WORKSHEET
Set objRS=objConn.Execute(strSQL)
%>
<table border="0">
<tr>
<%
'EXTRACT THE HEADER VALUES TO DISPLAY ON THE WEBPAGE
For xIndex=0 To objRS.Fields.Count-1
Response.Write("<th>" & objRS.Fields(xIndex).Name & "</th>")
Next
'ITERATE THROUGH THE EXCEL WORKSHEET AND UPDATE INTO THE ACCESS DATABASE
'NOTE THE VALUE OF xIndex IS DIFFERENT FOR BOTH ACCESS AND EXCEL ARRAY
'THIS IS TO TAKE IN ACCOUNT THE PRIMARY KEY VALUE FIELD IN ACCESS IF IT IS
'SET TO AUTO NUMBER
Do Until objRS.EOF
If IsNull(objRS.Fields(0).Value) Then Exit Do
rsAdd.AddNew
Response.Write("<tr>")
For xIndex=0 To objRS.Fields.Count-1
curValue = objRS.Fields(xIndex).Value
Response.Write("<td>" & objRS.Fields(xIndex).Value & "</td>")
rsAdd.Fields(xIndex+1).Value = objRS.Fields(xIndex).Value
Next
Response.Write("</tr>")
rsAdd.Update
objRS.MoveNext
Loop
%>
</tr>
</table>
</body>
</html>
<%
rsAdd.Close
Set rsAdd = Nothing
%>