Anzahl der Abfragewerte und Zielfelder stimmt nicht überein

  • VB6

Es gibt 13 Antworten in diesem Thema. Der letzte Beitrag () ist von robsen87.

    Anzahl der Abfragewerte und Zielfelder stimmt nicht überein

    Visual Basic-Quellcode

    1. Public Function WriteDBF()
    2. On Error GoTo ErrEnd
    3. If Format(Now, "DD.MM.YYYY") <> GetINISetting("DBF", "SaveDate", "") Then
    4. UnloadDBF
    5. LoadDBF
    6. End If
    7. dbc.Execute "INSERT INTO " & Format(GetINISetting("DBF", "SaveDate", ""), GetINISetting("General", "DBFFormat", "DDMMYY")) & GetINISetting("General", "DBFExtension", "LS") & " " & GetINISetting("DBF", "SQLHeader", "") & _
    8. "VALUES ('" & _
    9. GetINISetting("Record", "RecNo", "0") & "','" & _
    10. Datei.Typ & "','" & _
    11. Format(Now, "DD.MM.YYYY") & "','" & _
    12. Format(Now, "HH:NN:SS") & "','" & _
    13. Replace(fHandle.Data(1).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    14. IIf(fHandle.Data(7).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    15. Replace(fHandle.Data(2).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    16. IIf(fHandle.Data(8).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    17. Replace(fHandle.Data(3).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    18. IIf(fHandle.Data(9).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    19. Replace(fHandle.Data(4).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    20. IIf(fHandle.Data(10).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    21. IIf(fHandle.Data(6).Caption = GetINISetting("General", "TrueRead", ""), "i.O.", "n.i.O.") & "','" & _
    22. Replace(fHandle.Data(20).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    23. Replace(fHandle.Data(21).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    24. Replace(fHandle.Data(22).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    25. Replace(fHandle.Data(23).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    26. Replace(fHandle.Data(24).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    27. Replace(fHandle.Data(25).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    28. IIf(fHandle.Data(27).Caption = GetINISetting("General", "TrueRead", ""), "i.O.", "n.i.O.") & "','" & _
    29. fHandle.Data(49).Caption & "')"
    30. Exit Function
    31. ErrEnd:
    32. MsgBox "Die Funktion 'WriteDBF()' konnte nicht ausgeführt werden!" & vbCrLf & vbCrLf & _
    33. "Fehler: " & Err.Description & " (" & Err.Number & ")", vbCritical, "Fehler in Funktion WriteDBF"
    34. End Function


    kann mir bitte jemand sagen was hier nicht korrekt ist

    vielen dank im vorraus

    robsen87 schrieb:

    kann mir bitte jemand sagen was hier nicht korrekt ist


    Bei dir stimmt die Anzahl der Abfragewerte und Zielfelder stimmt nicht überein

    Ein Insert ist so aufgebaut:

    INSERT INTO Tabellenname(Spalte1,Spalte2,Spalte3,...,SpalteN) VALUES(Wert1,Wert2,Wert3,...,WertN)

    wobei eben genau so viele Spalten angegeben sein müssen wie Werte kommen.
    Beachte, daß du bei Dezimalzahlen als Dezimaltrennzeichen den Punkt verwenden mußt, da das Komma ja die einzelnen Werte voneinander trennt.

    Bei dir fehlt der Tabellenname und es sind 4 Spalten angegeben, jedoch 21 Werte

    Gruß
    Gaga
    der Teil:

    Visual Basic-Quellcode

    1. "INSERT INTO " & Format(GetINISetting("DBF", "SaveDate", ""), GetINISetting("General", "DBFFormat", "DDMMYY")) & GetINISetting("General", "DBFExtension", "LS") & " " & GetINISetting("DBF", "SQLHeader", "")


    ist eigentlich auch erstmal nur meine Angabe für die Bezeichnung meiner Tabelle
    ja also ich hab schon probiert die da irgendwie mit reinzubringen aber so wirklich gelungen ist mir das nicht. wie ist das außerdem wenn ich etliche spalten habe...muss ich die da alle ausführlich reinschreiben?

    du könntest mir ja mal anhand meines quelltextes die für dich korrekte lösung reinposten...wär cool
    Die richtige Lösung kann ich nicht posten, da ich keine Ahnung habe wie die Spalten heißen.

    Du mußt alle Spalten angeben denen du einen Wert zuweisen willst und allen angegebenen Spalten mußt du einen Wert zuweisen

    Visual Basic-Quellcode

    1. dbc.Execute "INSERT INTO " & Format(GetINISetting("DBF", "SaveDate", ""),
    2. GetINISetting("General", "DBFFormat", "DDMMYY")) &
    3. GetINISetting("General", "DBFExtension", "LS") & " " &
    4. GetINISetting("DBF", "SQLHeader", "") & _
    5. "(Name_der_Spalte_in_die_das_kommt," & _ '// GetINISetting("Record", "RecNo", "0")
    6. " Name_der_Spalte_in_die_das_kommt," & _ '// Datei.Typ
    7. " ..." & _ '// eben alle Spalten in der gleichen Reihenfolge
    8. " ..." & _ '// wie die Werte angeben
    9. " Name_der_Spalte_in_die_das_kommt)" & _ '// fHandle.Data(49).Caption
    10. "VALUES ('" & _
    11. GetINISetting("Record", "RecNo", "0") & "','" & _
    12. Datei.Typ & "','" & _
    13. Format(Now, "DD.MM.YYYY") & "','" & _
    14. Format(Now, "HH:NN:SS") & "','" & _
    15. Replace(fHandle.Data(1).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    16. IIf(fHandle.Data(7).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    17. Replace(fHandle.Data(2).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    18. IIf(fHandle.Data(8).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    19. Replace(fHandle.Data(3).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    20. IIf(fHandle.Data(9).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    21. Replace(fHandle.Data(4).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    22. IIf(fHandle.Data(10).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    23. IIf(fHandle.Data(6).Caption = GetINISetting("General", "TrueRead", ""), "i.O.", "n.i.O.") & "','" & _
    24. Replace(fHandle.Data(20).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    25. Replace(fHandle.Data(21).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    26. Replace(fHandle.Data(22).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    27. Replace(fHandle.Data(23).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    28. Replace(fHandle.Data(24).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    29. Replace(fHandle.Data(25).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    30. IIf(fHandle.Data(27).Caption = GetINISetting("General", "TrueRead", ""), "i.O.", "n.i.O.") & "','" & _
    31. fHandle.Data(49).Caption & "')"

    wobei du den Spaltenteil entsprechend ändern mußt, die richtigen Spaltennamen angeben und die Kommentare raus (Kommentare sind nach Leerzeichen-Unterstrich nicht erlaubt)

    Gruß
    Gaga
    ich hab noch ein bissl rumprobiert irgendwie die spalten noch mit reinzubekommen

    am ende sah das ganze jetzt so aus:

    Visual Basic-Quellcode

    1. dbc.Execute "INSERT INTO & Format(GetINISetting(""DBF"", ""SaveDate"", ""), GetINISetting(""General"", ""DBFFormat"", ""DDMMYYYY"")) & GetINISetting(""General"", ""DBFExtension"", ""LS"") & " & " & GetINISetting(""DBF"", ""SQLHeader"", "")" & _
    2. "(LFDNO, TYP, DATUM, UHRZEIT, MWTASTER1, ERGTASTER1, MWTASTER2, ERGTASTER2, MWTASTER31, ERGTASTER3, MWTASTER4, ERGTASTER4, GESAMTST7," & _
    3. "SWWEGMIN, SWWEGMAX, SWKRAFTMIN, SWKRAFTMAX, IWKRAFTMIN, IWKRAFTMAX, GESAMTST8, NESTNUMMER)" & _
    4. "VALUES ('" & _
    5. GetINISetting("Record", "RecNo", "0") & "','" & _
    6. Datei.Typ & "','" & _
    7. Format(Now, "DD.MM.YYYY") & "','" & _
    8. Format(Now, "HH:NN:SS") & "','" & _
    9. Replace(fHandle.Data(1).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    10. IIf(fHandle.Data(7).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    11. Replace(fHandle.Data(2).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    12. IIf(fHandle.Data(8).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    13. Replace(fHandle.Data(3).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    14. IIf(fHandle.Data(9).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    15. Replace(fHandle.Data(4).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    16. IIf(fHandle.Data(10).Caption = GetINISetting("General", "TrueRead", ""), "n.i.O.", "i.O.") & "','" & _
    17. IIf(fHandle.Data(6).Caption = GetINISetting("General", "TrueRead", ""), "i.O.", "n.i.O.") & "','" & _
    18. Replace(fHandle.Data(20).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    19. Replace(fHandle.Data(21).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    20. Replace(fHandle.Data(22).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    21. Replace(fHandle.Data(23).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    22. Replace(fHandle.Data(24).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    23. Replace(fHandle.Data(25).Caption, ",", ".", 1, -1, vbTextCompare) & "','" & _
    24. IIf(fHandle.Data(27).Caption = GetINISetting("General", "TrueRead", ""), "i.O.", "n.i.O.") & "','" & _
    25. fHandle.Data(49).Caption & "')"


    das programm lässt sich auch so erstmal starten aber wenn dann das programm gestartet ist kommt gleich die fehlermeldung: [Microsoft][ODBC dBase Driver]Syntaxfehler in der INSERT INTO-Anweisung

    außerdem bekomme ich jetzt noch eine zweite fehlermeldung: Objektvariable oder With-Blockvariable nicht festgelegt(91)

    diese fehler tritt aber in folgendem abschnitt auf

    Visual Basic-Quellcode

    1. Public Function UnloadDBF()
    2. 'End Function
    3. On Error GoTo ErrEnd
    4. Set dbc = Nothing
    5. dbc.Close
    6. Exit Function
    7. ErrEnd:
    8. MsgBox "Die Funktion 'UnloadDBF()' konnte nicht ausgeführt werden!" & vbCrLf & vbCrLf & _
    9. "Fehler: " & Err.Description & " (" & Err.Number & ")", vbCritical, "Fehler in Funktion UnloadDBF"
    10. End Function




    ich hoffe ihr könnt mir noch ein bisschen weiter helfen...

    robsen87 schrieb:


    fehlermeldung: [Microsoft][ODBC dBase Driver]Syntaxfehler in der INSERT INTO-Anweisung

    Mach mal anstatt dem dbc.Execute "INSERT INTO ...
    einen Debug.Print "INSERT INTO ...
    und schau dir im Direktfenster an was an die Datenbank geschickt werden soll und/oder poste das.

    robsen87 schrieb:

    außerdem bekomme ich jetzt noch eine zweite fehlermeldung: Objektvariable oder With-Blockvariable nicht festgelegt(91)

    Visual Basic-Quellcode

    1. Set dbc = Nothing
    2. dbc.Close '// <- Was willst du hier Schließen, du hast in der Zeile vorher den Verweis gelöscht

    Dreh die zwei Zeilen um

    Gruß
    Gaga
    also bei debug.print bringt er:

    INSERT INTO & Format(GetINISetting("DBF", "SaveDate", "), GetINISetting("General", "DBFFormat", "DDMMYYYY")) & GetINISetting("General", "DBFExtension", "LS") & & GetINISetting("DBF", "SQLHeader", ")(LFDNO, TYP, DATUM, UHRZEIT, MWTASTER1, ERGTASTER1, MWTASTER2, ERGTASTER2, MWTASTER31, ERGTASTER3, MWTASTER4, ERGTASTER4, GESAMTST7,SWWEGMIN, SWWEGMAX, SWKRAFTMIN, SWKRAFTMAX, IWKRAFTMIN, IWKRAFTMAX, GESAMTST8, NESTNUMMER)VALUES ('6','Kern Liebers - kl. Kalotte','14.08.2008','09:34:11','5.700','i.O.','3.300','i.O.','0.000','i.O.','0.000','i.O.','n.i.O.','00.0','00.0','00.0','00.0','00.0','00.0','n.i.O.','0')

    es kam jetzt auf jedenfall auch ertmal keine fehlermeldung mehr aber die eigentliche tabelle wurde natürlich nicht angelegt
    Das wundert mich nicht, nach INTO muß der Name der Tabelle kommen und bei dir steht dort
    & Format(GetINISetting("DBF", "SaveDate", "),...

    Ich glaube nicht, dass die Tabelle so heißt.

    Übrigends: Wenn im Tabellennamen Lerrzeichen oder sonstige Sonderzeichen sind, muss der Tabellenname in eckige Klammern.

    Visual Basic-Quellcode

    1. Debug.Print "INSERT INTO [" & Format(GetINISetting("DBF", "SaveDate", ""), GetINISetting("General", "DBFFormat", "DDMMYYYY")) & GetINISetting("General", "DBFExtension", "LS") & " & " & GetINISetting("DBF", "SQLHeader", "") & "]" & _
    2. "(LFDNO, TYP, DATUM, UHRZEIT, MWTASTER1, ERGTASTER1, MWTASTER2, ERGTASTER2, MWTASTER31, ERGTASTER3, MWTASTER4, ERGTASTER4, GESAMTST7," & _
    3. "SWWEGMIN, SWWEGMAX, SWKRAFTMIN, SWKRAFTMAX, IWKRAFTMIN, IWKRAFTMAX, GESAMTST8, NESTNUMMER)" & _
    4. "VALUES ('" & _
    5. ...
    nein...genau so heißen soll die tabelle natürlich nicht. der name soll immer automatisch angelegt werden in verbindung mit dem heutigen datum und sonstigem

    also als es schon einigermaßen funktioniert hatte wurde zum beispiel die 130808LS.dbf angelgt, aber in der standen dann keine werte drin sondern nur die spaltenüberschriften

    ich denke nicht dass ich in der schreibweise nochmal irgendwie die spaltennamen einbringen muss...die waren ja dann eben schon drin

    robsen87 schrieb:

    nein...genau so heißen soll die tabelle natürlich nicht. der name soll immer automatisch angelegt werden in verbindung mit dem heutigen datum und sonstigem


    :?: Soll das heißen, dass du die Tabelle erstellen willst :?:
    Mit INSERT INTO fügst du Daten in eine bestehende Tabelle ein, zum Erstellen einer Tabelle braucht man CREATE TABLE