[Help]saving pictures in database error - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

[Help]saving pictures in database error

wilenwilen Posts: 1Member
[code]Dim con As New ADODB.Connection
Dim com As New ADODB.Command
Dim sql As String
Dim rec As ADODB.Recordset




con.ConnectionString = DBconnection
con.CursorLocation = adUseClient
con.Open

com.ActiveConnection = con

sql = "insert into gallery(picture) values " & _
" '" & (cdopen.FileName) & "' "



com.CommandText = sql
Set rec = com.Execute [color=Red]<-- im having problem with this[/color]
[/code]

Comments

  • dokken2dokken2 Posts: 532Member

    : com.CommandText = sql
    : Set rec = com.Execute [color=Red]<-- im having problem with this[/color]
    : [/code]:
    :


    you can not assign a connection-command text to a recordset.
    here's an example using the connection.execute method-

    [code]
    Public Function AdoUtilityUpdate(ByRef MyConType As ContractType) As Boolean
    Dim cn As ADODB.Connection
    Dim sCon As String
    Dim Sql As String
    Dim MyTmp As ContractType
    Dim errCount As Integer

    On Error GoTo erh

    'CONNECTION STRING
    sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "User ID=Admin;Password=;" & _
    "Data Source=" & mDataSourceUtil & ";" & _
    "Persist Security Info=False"

    Sql = "UPDATE Contract SET "

    'CREATE NEW ADO CONNECTION
    Set cn = New ADODB.Connection
    'OPEN CONNECTION WITH CONNECTION STRING AND EXECUTION SQL
    cn.Open sCon
    'EXECUTE SQL
    cn.Execute Sql

    xit1:
    'CLOSE/RELEASE RESOURCES
    cn.Close
    xit2:
    Set cn = Nothing
    If errCount = 0 Then MsgBox "Update Successful", vbInformation, "Sql status"
    Exit Function

    erh:
    MsgBox Err.Description, vbCritical, Err.Number
    AdoUtilityUpdate = True 'FAIL
    errCount = errCount + 1
    If errCount = 1 Then Resume xit1 Else Resume xit2
    End Function
    [/code]
Sign In or Register to comment.