Hallo,
Ich möchte gerne Bilder in MySQL speichern.
Mein Quellcode sieht folgendermaßen aus:
<pre>
Private Sub cmd_Bild_speichern_Click()
Dim Bild_Pfad As String 'Variable zum Speichern des Pfades
Dim SQL_Befehl As String 'Variable zum Speichern des SQL_Befehles
Dim RS_Bild_S As ADODB.Recordset 'Recordset zum Absetzen des SQL_Befehls
Dim Doc_Bild_S As ADODB.Stream 'Stream zum Speichern des Bildes
Dim conn_Bild As ADODB.Connection 'Spezielle Verbindung zum Bild-Speichern
'Falls Pfad falsch
On Error GoTo Fehler_Pfad
Bild_Pfad = Right$(Label10.Caption, Len(Label10.Caption) - 6)
On Error GoTo 0
'Falls Pfad = ""
If Bild_Pfad = "" Then
MsgBox Fehler_Bild_Mld, vbCritical, Fehler_Bild_Titel
Exit Sub
End If
'spezeille Verbindung öffnen
Set conn_Bild = New ADODB.Connection
With conn_Bild
.ConnectionString = "DRIVER={" & sSQLDB_DRV & "};" _
& "SERVER=" & sSQLDB_SRV & ";" _
& "DATABASE=" & sSQLDB_DAT & ";" _
& "UID=" & sSQLDB_UID & ";" _
& "PWD=" & sSQLDB_PWD & ";" _
& "OPTION=" & 2 + 8 + 16384
.CursorLocation = adUseServer
.Open
End With
'Stream öffnen
Set Doc_Bild_S = New ADODB.Stream
With Doc_Bild_S
.Type = adTypeBinary
.Open
.LoadFromFile Bild_Pfad
End With
'SQL_Befehl zusammensetzen
SQL_Befehl = "Select * from werkzeug where kat01 = " & _
Left$(Combo_Kat01.Text, 1) & " and kat02 = " & _
Left$(Combo_Kat02.Text, 2) & " and kat03 = " & _
Left$(Combo_Kat03.Text, 2) & " and w_nr = " & _
txt_W_Nr.Text & ";"
'RS öffnen
Set RS_Bild_S = New ADODB.Recordset
With RS_Bild_S
.Open SQL_Befehl, conn_Bild, adOpenDynamic, adLockOptimistic
'Update durchführen
.Fields!w_Bild_url = Doc_Bild_S.Read
.Update
.Close
End With
'steam Schließen
Doc_Bild_S.Close
'Pfad aus Label10 löschen
Label10.Caption = "Pfad: "
'Verbindung schließen
conn_Bild.Close
Exit Sub
'Fehlerbehandlung
Fehler_Pfad:
MsgBox Fehler_Bild_Mld, vbCritical, Fehler_Bild_Titel
</pre>
In den Zeilen <b>.Fields!w_Bild_url = doc_Bild_S.Read</B> bzw. <B>.Update</B> treten Fehler auf, je nachdem wie ich die Verbindung, bzw. das Recordset öffne.
Ich hoffe, jemand kann mir helfen.
Danke im Voraus.
Gruß
tobias
Ich möchte gerne Bilder in MySQL speichern.
Mein Quellcode sieht folgendermaßen aus:
<pre>
Private Sub cmd_Bild_speichern_Click()
Dim Bild_Pfad As String 'Variable zum Speichern des Pfades
Dim SQL_Befehl As String 'Variable zum Speichern des SQL_Befehles
Dim RS_Bild_S As ADODB.Recordset 'Recordset zum Absetzen des SQL_Befehls
Dim Doc_Bild_S As ADODB.Stream 'Stream zum Speichern des Bildes
Dim conn_Bild As ADODB.Connection 'Spezielle Verbindung zum Bild-Speichern
'Falls Pfad falsch
On Error GoTo Fehler_Pfad
Bild_Pfad = Right$(Label10.Caption, Len(Label10.Caption) - 6)
On Error GoTo 0
'Falls Pfad = ""
If Bild_Pfad = "" Then
MsgBox Fehler_Bild_Mld, vbCritical, Fehler_Bild_Titel
Exit Sub
End If
'spezeille Verbindung öffnen
Set conn_Bild = New ADODB.Connection
With conn_Bild
.ConnectionString = "DRIVER={" & sSQLDB_DRV & "};" _
& "SERVER=" & sSQLDB_SRV & ";" _
& "DATABASE=" & sSQLDB_DAT & ";" _
& "UID=" & sSQLDB_UID & ";" _
& "PWD=" & sSQLDB_PWD & ";" _
& "OPTION=" & 2 + 8 + 16384
.CursorLocation = adUseServer
.Open
End With
'Stream öffnen
Set Doc_Bild_S = New ADODB.Stream
With Doc_Bild_S
.Type = adTypeBinary
.Open
.LoadFromFile Bild_Pfad
End With
'SQL_Befehl zusammensetzen
SQL_Befehl = "Select * from werkzeug where kat01 = " & _
Left$(Combo_Kat01.Text, 1) & " and kat02 = " & _
Left$(Combo_Kat02.Text, 2) & " and kat03 = " & _
Left$(Combo_Kat03.Text, 2) & " and w_nr = " & _
txt_W_Nr.Text & ";"
'RS öffnen
Set RS_Bild_S = New ADODB.Recordset
With RS_Bild_S
.Open SQL_Befehl, conn_Bild, adOpenDynamic, adLockOptimistic
'Update durchführen
.Fields!w_Bild_url = Doc_Bild_S.Read
.Update
.Close
End With
'steam Schließen
Doc_Bild_S.Close
'Pfad aus Label10 löschen
Label10.Caption = "Pfad: "
'Verbindung schließen
conn_Bild.Close
Exit Sub
'Fehlerbehandlung
Fehler_Pfad:
MsgBox Fehler_Bild_Mld, vbCritical, Fehler_Bild_Titel
</pre>
In den Zeilen <b>.Fields!w_Bild_url = doc_Bild_S.Read</B> bzw. <B>.Update</B> treten Fehler auf, je nachdem wie ich die Verbindung, bzw. das Recordset öffne.
Ich hoffe, jemand kann mir helfen.
Danke im Voraus.
Gruß
tobias
Comment