Benutzung:
Dim fishe() As String = {"Goldfische", "Blas"}
Dim werte() As String = {"24 Goldies", "37 Blas"}
MsgBox(SQL_Build_INSERT("Tiere", fishe, werte))
Ergebis:
INSERT INTO Tiere (`Goldfische`, `Blas`) VALUES ('Goldfische', 'Blas')
Hoffe es hilft euch weiter...
GreeZ TTP
Private Function SQL_Build_INSERT(ByVal Tablename As String, ByVal Felder As Array, ByVal Werte As Array) As String
Dim res As String = Nothing
If Tablename = Nothing Or Felder.Length = 0 Or Felder.Length <> Werte.Length Then
Throw New Exception("Tablename or Felder = NOTHING or Felder.Length <> Werte.Length")
End If
Dim ai As Integer = Felder.Length
Dim i As Integer
res = "INSERT INTO " & Tablename & " ("
For i = 0 To Felder.Length - 1
If i = 0 Then
res &= "`" & Felder(i).ToString & "`"
Else
res &= ", `" & Felder(i).ToString & "`"
End If
Next
res &= ") VALUES ("
For i = 0 To Werte.Length - 1
If i = 0 Then
If Werte(i).ToString = Nothing Then
res &= "NULL"
Else
res &= "'" & Felder(i).ToString & "'"
End If
Else
If Werte(i).ToString = Nothing Then
res &= ", NULL"
Else
res &= ", '" & Felder(i).ToString & "'"
End If
End If
Next
res &= ")"
Return res
End Function
5 Kommentare zum Snippet