Hej :)
Har pillat lite med det hela under kvällen och fått ihop något som jag tror fungerar...
Postar hela koden här även att den innehåller asp.... Kanske skulle varit i asp-forumet istället... men, men...
'Loopen
while not objFile.atendofstream
'Villkor för att flusha
iCounter = iCounter +1
if iCounter mod 100 = 0 then
Response.write ("<script>document.getElementById(""progress"").innerHTML=""" & iCounter & """;</script>")
Response.flush
end if
sLine = objFile.ReadLine
'Ta ut de olika delarna ur textfilen
sEnumber = SQLSafe(Trim(Mid(sLine, 1, 8)))
sArticlename = SQLSafe(Trim(Mid(sLine, 39, 46)))
sUnit = SQLSafe(Trim(Lcase(Mid(sLine, 21, 3))))
sCategory = SQLSafe(Trim(Mid(sLine, 17, 4)))
curPrice = SQLSafe(Trim(Mid(sLine, 9, 8)))
'Uppdatera tblExArticle om artikeln redan finns
sSQL = "UPDATE tblExArticle SET eNumber = '" & sEnumber & "', articleName = '" & sArticleName & "', articleUnit = '" & sUnit & "' WHERE eNumber = '" & sEnumber & "'"
objConn.Execute sSQL, lngRA, 128
if lngRa = 0 then
'Lägga till artikeln i tblExArticle om den inte finns
sSQL = "INSERT INTO tblExArticle (eNumber, articleName, articleUnit) VALUES ('" & sEnumber & "', '" & sArticleName & "', '" & sUnit & "')"
objConn.Execute sSQL,,128
End if
'Uppdatera tblExPrice om artikeln redan finns
sSQL = "UPDATE tblExPrice SET eNumber = '" & sEnumber & "', articleSupplierId = '" & iSupplierId & "', articlePrice = " & curPrice & ", " &_
"articleCategory = '" & sCategory & "' WHERE eNumber = '" & sEnumber & "' AND articleSupplierId = " & iSupplierId
objConn.Execute sSQL, lngRA, 128
if lngRA = 0 then
'Lägga till artikeln i tblExPrice om den inte finns
sSQL = "INSERT INTO tblExPrice (eNumber, articleSupplierId, articlePrice, articleCategory) " &_
"VALUES ('" & sEnumber & "', " & iSupplierId & ", " & curPrice & ", '" & sCategory & "')"
objConn.Execute sSQL
End If
'Skapa en variabel innehållandes alla E-numrena från prilistefilen
sAllEnumbers = sAllEnumbers & "'" & sEnumber & "',"
wend
'Plocka bort det sista kommat i strängen med alla E-numrena
sAllEnumbers = Left(sAllEnumbers,len(sAllEnumbers)-1)
'Ta bort alla Artiklar som inte finns med i den nya prislistan från tblExArticle
sSQL = "DELETE FROM tblExArticle WHERE NOT exists " &_
"(SELECT * FROM tblExPrice WHERE tblExPrice.eNumber = tblExArticle.eNumber AND tblExPrice.articleSupplierId <> " & iSupplierId & ") " &_
"and eNumber not in ("& sAllEnumbers &")"
objConn.Execute(sSQL)
'Ta bort alla artiklar som inte finns i den nya prislistan från tblExPrice
sSQL = "DELETE FROM tblExPrice WHERE eNumber NOT IN ("& sAllEnumbers &") And ArticleSupplierId = " & iSupplierId & ""
objConn.Execute(sSQL)
Är detta en bra lösning eller går det att göra bättre... strängen med alla enummer sAllEnumbers blir ju väldigt stot tex.. en prislista innehåller ca 60 000 artiklar.
Tacksam för feedback och synpunkter...
Mvh
henrik