så skulle det køre - det er lige lagt lidt test ind på at den ikke kommer til at starte forfra (fx ved manglende data i en linje).
Jeg har rette i feltnavne (det er noget tid siden, jeg lavede noget i asp): åbenbart når jeg har fx product-id så trækker den id fra product - så der er ikke bindestreger mere.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta http-equiv = "Content-Type" content = "text/html; charset = iso-8859-1">
<title></title>
</head><body>
<%
LANGUAGE = VBScript
LCID = 1030
Function findfelt(felt,slutdata)
start = instr(felt,helesiden,"<td") +4
slut = instr(start,helesiden,"</td")
if slut < felt or slut > slutdata then
findfelt = ""
else
findfelt = trim(mid(helesiden, start, slut-start))
end if
End Function
On Error Resume Next
linket = "
http://www.nationalliga.dk/test/test.asp" Set whttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
whttp.Open "GET",linket
whttp.Send
If whttp.Status <> 200 Then
Response.Write "Der opstod en fejl :<hr>" & vbCrLf
Response.Write "<P>fejlkode " & whttp.Status & "<Br>" & whttp.StatusText & "<hr>"
Else
helesiden = whttp.ResponseText
helesiden = replace(helesiden," "," ")
helesiden = replace(helesiden," "," ")
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open "driver = {Microsoft Access Driver (*.mdb)};dbq = " &Server.MapPath("../db/livefeeddata.mdb")
' starter læsning fra efter første linjen med overskrifter
start = instr(1,helesiden,"</tr")
' returnerer 0 hvis ikke flere <tr...
fleredata = instr(start,helesiden,"<tr")
while fleredata > 0
slutdata = instr(fleredata,helesiden,"</tr")
felt = instr(fleredata,helesiden,vbCrLf)
ProductId = CInt(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Title = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Status = CInt(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Quantity = CInt(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Price = CDbl(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Fromprice = CDbl(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Savings = CDbl(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Shipping = CDbl(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Orders = CInt(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Quantityordered = CInt(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Ordertypes = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Promocode = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Suppliername = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Suppliermail = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Category = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Created = CDate(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Updated = CDate(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Firsttransaction = CDate(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Lasttransaction = CDate(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Avancepct = CDbl(findfelt(felt,slutdata))
felt = instr(felt+2,helesiden,vbCrLf)
Omsaetningtilfalder = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Ansvarligsaelger = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Omsaetningsgruppe = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
KiCgruppe = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Overkategori = findfelt(felt,slutdata)
felt = instr(felt+2,helesiden,vbCrLf)
Underkategori = findfelt(felt,slutdata)
SQL = "INSERT INTO livedata (ProductId, Title, Status, Quantity, Price, Fromprice, Savings, Shipping, Orders, Quantityordered, Ordertypes, Promocode, Suppliername, Suppliermail, Category, Created, Updated, Firsttransaction, Lasttransaction, Avancepct, Omsaetningtilfalder, Ansvarligsaelger, Omsaetningsgruppe, KiCgruppe, Overkategori, Underkategori) VALUES(" & ProductId & ",'" & Title & "'," & Status & "," & Quantity & "," & Price & "," & Fromprice & "," & Savings & "," & Shipping & "," & Orders & "," & Quantityordered & ",'" & Ordertypes & "','" & Promocode & "','" & Suppliername & "','" & Suppliermail & "','" & Category & "',#" & Created & "#,#" & Updated & "#,#" & Firsttransaction & "#,#" & Lasttransaction & "#," & Avancepct & ",'" & Omsaetningtilfalder & "','" & Ansvarligsaelger & "','" & Omsaetningsgruppe & "','" & KiCgruppe & "','" & Overkategori & "','" & Underkategori & "')"
Connect.Execute(SQL)
fleredata = instr(fleredata+5,helesiden,"<tr")
wend
Connect.close
set Connect = nothing
response.write "Databasen er ajourført.<hr>"
End If
On Error Goto 0
%>
</body>
</html>