VB6, MySql, Stream Image to Blob, Null Value Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michels287
    New Member
    • Mar 2008
    • 20

    #1

    VB6, MySql, Stream Image to Blob, Null Value Error

    With a single record in my table, I can use this code:


    Code:
    Private Sub Command1_Click()
    
    Set cn = New ADODB.Connection
    cn.Open "Provider=MSDASQL.1;Persist Security Info=False;" & _
          "Data Source=localhost;Initial Catalog=testdb"
    
    Set rs = New ADODB.Recordset
    rs.Open "Select * from album", cn, adOpenKeyset, adLockOptimistic
    
    Set mstream = New ADODB.Stream
    mstream.Type = adTypeBinary
    mstream.Open
    mstream.LoadFromFile "C:\Users\Chris\Desktop\sample.jpg"
    rs.Fields("picture").Value = mstream.Read
    rs.Update
    
    rs.Close
    cn.Close
    
    End Sub
    My general declarations:


    Code:
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim mstream As ADODB.Stream
    When the command is pressed the same record obviously would update with a different picture (assuming I change the file path of course). I do not get a null error there.

    I would like to constantly add a new record instead of updating the same one.

    If I use rs.AddNew just above, "rs.Fields("pic ture").Value = mstream.Read"

    I get the null value error. It says that the column "picture" cannot have a null value. Can someone please help me?

    Thanks for the attention.
Working...