04. januar 2001 - 13:41Der er
40 kommentarer og 1 løsning
Type mismatch???
Hejsa!
Jeg har lavet en noget avanceret if-clause der kører på forskellige forudsætninger ved update af nogle upload files.
Min If-statement ser sådan ud:
If rs1(\"Dump\") is nothing AND dump1 = \"\" Then sql1 = Nothing End if If rs1(\"Dump\") = \"%\" AND dump1 = \"\" Then sql1 = Nothing End if If rs1(\"Dump\") is nothing AND dump1 = \"%\" Then sql1 = \"INSERT INTO Film_dump_side1 (Dump) VALUES (\'\"&Upload.Files(\"dump1\").ExtractFileName&\"\') WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" Connect.Execute(sql1) End if If rs1(\"Dump\") = \"%\" AND dump1 = \"%\" Then sql1 = \"UPDATE Film_dump_side1 SET Dump=\'\"&Upload.Files(\"dump1\").ExtractFileName&\"\' WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" Connect.Execute(sql1) End if
Jeg får en type mismatch fejl i den første linie, men kan ikke se fejlen....har efterhånden set mig blind på koderne.
Hvis du skal tjecke om et felt er tomt skal du bruge isNull() ellers skal du gøre sådan her: rs1(\"Dump\") = \"\" eller rs1(\"Dump\") = \" \", det er en spejet sag at undersøge om et felt er tomt eller om det er Null....Nogen databaser fortolker Null som et mellemrum, spørg mig ikke hvorfor, men sådan er det..... Er feltet tomt eller indeholder det et mellemrum ?????
Fejlen du får betyder at du tester dit datafetl for en forkert type. f.eks, hvis dit felt er et tekstfelt og du forsøger at teste om det indeholder en dato. Har haft samme problem selv, og fandt ikke anden løsning end at lægge en værdi i feltet når posten oprettes, som f.eks. \"none\" se også http://www.eksperten.dk/spm/40292
eller prøv i første omgang med : <% if rs1(\"Dump\") = \"\" Amd dump1=\"\" %>
OK, lav det som i http://www.eksperten.dk/spm/40292 Du laver en standard værdi i alle felterne, f.eks. \'empty\', eller \'none\' Det viser sig at ASP har meget svært ved at tolke NULL\'s fra en Access base.... Hvorfor ved jeg ikke. Anyway, så bruger du denne kode : ******************************************** If rs1(\"Dump\") = \"none\" AND dump1 = \"%\" Then sql1 = \"INSERT INTO Film_dump_side1 (Dump) VALUES (\'\"&Upload.Files(\"dump1\").ExtractFileName&\"\') WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" Connect.Execute(sql1) End if If rs1(\"Dump\") = \"%\" AND dump1 = \"%\" Then sql1 = \"UPDATE Film_dump_side1 SET Dump=\'\"&Upload.Files(\"dump1\").ExtractFileName&\"\' WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" Connect.Execute(sql1) End if ********************************************
Der er heller ikke nogen grund til at lave check\'s på noget hvor du hvis tjecket går igennem ikke gør noget.....SÅ de to sidste er nok...
OKay du kan hacke dig vej igennem uden at ændre i din base sådan her :
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' If (len(rs1(\"Dump\") & \"test\") = 4) AND dump1 = \"%\" Then sql1 = \"INSERT INTO Film_dump_side1 (Dump) VALUES (\'\"&Upload.Files(\"dump1\").ExtractFileName&\"\') WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" Connect.Execute(sql1) End if If rs1(\"Dump\") = \"%\" AND dump1 = \"%\" Then sql1 = \"UPDATE Film_dump_side1 SET Dump=\'\"&Upload.Files(\"dump1\").ExtractFileName&\"\' WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" Connect.Execute(sql1) End if \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\' Da string1 & Null giver string1 kan man ved at tjecke om længden er længden af striong1 afgøre om Null er Null. Tosset men det skulle virke....
Set Dump = Upload.Files(\"dump\") If Dump is nothing Then Dump1 = \"\" Else Dump1 = Dump.ExtractFileName End if
Set Side1 = Upload.Files(\"side1\") If Side1 is nothing Then Side11 = \"\" Else Side11 = Side1.ExtractFileName End if
Set Galleri1 = Upload.Files(\"galleri1\") If Galleri1 is nothing then Galleri11 = \"\" Else Galleri11 = Galleri1.ExtractFileName End if
Set Galleri2 = Upload.Files(\"galleri2\") If Galleri2 is nothing Then Galleri21 = \"\" Else Galleri21 = Galleri2.ExtractFileName End if
Set Galleri3 = Upload.Files(\"galleri3\") If Galleri3 is nothing Then Galleri31 = \"\" Else Galleri31 = Galleri3.ExtractFileName End if
Set Galleri4 = Upload.Files(\"galleri4\") If Galleri4 is nothing Then Galleri41 = \"\" Else Galleri41 = Galleri4.ExtractFileName End if
Set Galleri5 = Upload.Files(\"galleri5\") If Galleri5 is nothing Then Galleri51 = \"\" Else Galleri51 = Galleri5.ExtractFileName End if
Set Galleri6 = Upload.Files(\"galleri6\") If Galleri6 is nothing Then Galleri61 = \"\" Else Galleri61 = Galleri6.ExtractFileName End if
Set Galleri7 = Upload.Files(\"galleri7\") If Galleri7 is nothing Then Galleri71 = \"\" Else Galleri71 = Galleri7.ExtractFileName End if
Set Galleri8 = Upload.Files(\"galleri8\") If Galleri8 is nothing Then Galleri81 = \"\" Else Galleri81 = Galleri8.ExtractFileName End if
Set Galleri9 = Upload.Files(\"galleri9\") If Galleri9 is nothing Then Galleri91 = \"\" Else Galleri91 = Galleri9.ExtractFileName End if
Set Galleri10 = Upload.Files(\"galleri10\") If Galleri10 is nothing Then Galleri101 = \"\" Else Galleri101 = Galleri10.ExtractFileName End if
Set Poster1 = Upload.Files(\"poster1\") If Poster1 is nothing Then Poster11 = \"\" Else Poster11 = Poster1.ExtractFileName End if
Set Poster2 = Upload.Files(\"poster2\") If Poster2 is nothing Then Poster21 = \"\" Else Poster21 = Poster2.ExtractFileName End if
Set Poster3 = Upload.Files(\"poster3\") If Poster3 is nothing Then Poster31 = \"\" Else Poster31 = Poster3.ExtractFileName End if
Set Trailer1 = Upload.Files(\"trailer1\") If Trailer1 is nothing Then Trailer11 = \"\" Else Trailer11 = Trailer1.ExtractFileName End if
Set Trailer2 = Upload.Files(\"trailer2\") If Trailer2 is nothing Then Trailer21 = \"\" Else Trailer21 = Trailer2.ExtractFileName End if
\'sætter if-clauses for Film-Dump If rs1(\"Dump\") = \" \" AND dump1 = \" \" Then sql1 = Nothing End if If rs1(\"Dump\") = \"%\" AND dump1 = \" \" Then sql1 = Nothing End if If rs1(\"Dump\") is nothing AND dump1 = \"%\" Then sql1 = \"INSERT INTO Film_dump_side1 (Dump) VALUES (\'\"&Upload.Files(\"dump1\").ExtractFileName&\"\') WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" Connect.Execute(sql1) End if If rs1(\"Dump\") = \"%\" AND dump1 = \"%\" Then sql1 = \"UPDATE Film_dump_side1 SET Dump=\'\"&Upload.Files(\"dump1\").ExtractFileName&\"\' WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" Connect.Execute(sql1) End if
\'sætter if-clauses for Film-Side1 \'If rs1(\"Side1\") is nothing AND side11 = \"\" Then \' sql2 = Nothing \'End if \'If rs(\"Side1\") = \"%\" AND side11 = \"\" Then \' sql2 = Nothing \'End if \'If rs(\"Side1\") is nothing AND side11 = \"%\" Then \' sql2 = \"INSERT INTO Film_dump_side1 (Side1) VALUES (\'\"&Upload.Files(\"side11\").ExtractFileName&\"\') WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" \' Connect.Execute(sql2) \'End if \'If rs(\"Side1\") = \"%\" AND side11 = \"%\" Then \' sql2 = \"UPDATE Film_dump_side1 SET Side1=\'\"&Upload.Files(\"side11\").ExtractFileName&\"\' WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" \' Connect.Execute \'End if
\'sætter if-clauses for Galleri1 \'If rs2(\"Galleri1\") is nothing AND galleri11 = \"\" Then \' sql3 = Nothing \'End if \'If rs2(\"Galleri1\") = \"%\" AND galleri11 = \"\" Then \' sql3 = Nothing \'End if \'If rs2(\"Galleri1\") is nothing AND galleri11 = \"%\" Then \' sql3 = \"INSERT INTO Film_galleri (Galleri1) VALUES (\'\"&Upload.Files(\"galleri11\").extractfilename&\"\') WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" \' Connect.Execute(sql3) \'End if \'If rs2(\"Galleri1\") = \"%\" AND galleri11 = \"%\" Then \' sql3 = \"UPDATE Film_galleri SET Galleri1=\'\"&Upload.Files(\"galleri11\").ExtractFileName&\"\' WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" \' Connect.Execute(sql3) \'End if
\'sætter if-clauses for Galleri2 \'If rs2(\"Galleri2\") is nothing AND galleri21 = \"\" Then \' sql4 = Nothing \'End if \'If rs2(\"Galleri2\") = \"%\" AND galleri21 = \"\" Then \' sql4 = Nothing \'End if \'If rs2(\"Galleri2\") is nothing AND galleri21 = \"%\" Then \' sql4 = \"INSERT INTO Film_galleri (Galleri2) VALUES (\'\"&Upload.Files(\"galleri21\").ExtractFileName&\"\') WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" \' Connect.Execute(sql4) \'End if \'If rs2(\"Galleri2\") = \"%\" AND galleri21 = \"%\" Then \' sql4 = \"UPDATE Film_galleri SET Galleri2=\'\"&Upload.Files(\"galleri21\").ExtractFileName&\"\' WHERE Edbnr=\'\"&Request.QueryString(\"edbnr\")&\"\'\" \' Connect.Execute(sql4) \'End if
\'sætter if-clauses for Galleri3
\'sætter if-clauses for Galleri4
\'sætter if-clauses for Galleri5
\'sætter if-clauses for Galleri6
\'sætter if-clauses for Galleri7
\'sætter if-clauses for Galleri8
\'sætter if-clauses for Galleri9
\'sætter if-clauses for Galleri10
\'sætter if-clauses for Poster1 \'sql3 = \"UPDATE Film_poster SET Poster1=\'\"&Upload.Files(\"poster11\").ExtractFileName&\"\', Poster2=\'\"&Upload.Files(\"poster21\").ExtractFileName&\"\', Poster3=\'\"&Upload.Files(\"poster31\").ExtractFileName&\"\' WHERE Edbnr=\"&Request.QueryString(\"edbnr\")&\"\" \'Connect.Execute(sql3)
\'sætter if-clauses for Poster2
\'sætter if-clauses for Poster3
\'sætter if-clauses for Trailer1
\'sætter if-clauses for Trailer2 \'sql4 = \"UPDATE Film_trailer SET Trailer1=\'\"&Upload.Files(\"trailer11\").ExtractFileName&\"\', Trailer2=\'\"&Upload.Files(\"trailer21\").ExtractFileName&\"\' WHERE Edbnr=\"&Request.QueryString(\"edbnr\")&\"\" \'Connect.Execute(sql4)
Set Upload = Nothing Connect.Close Set Connect = Nothing
Det du skal bruge er en TrimNull funktion. En funktion som checker om feltet indeholder en gyldig strengværdi. Problemmet er at access laver feltets værdi som null, hvis det er tomt, hvilket jo er logisk nok.
Her er funktionen, det skal lige siges at den IKKE virker på Notater:
Private Function TrimNull(startstr) As String \'Shared function for removeing null values/objects If VarType(startstr) = vbNull Then TrimNull = \"\" ElseIf IsNull(startstr) = True Then TrimNull = \"\" Else TrimNull = startstr End If End Function
Jeg er ikke sikker på at den virker i asp, da den er skrevet til vb.
Udover det, skal du nok ændre nogle af dine AND oberatorer til OR.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.