By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,627 Members | 2,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,627 IT Pros & Developers. It's quick & easy.

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

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  3. Set cn = New ADODB.Connection
  4. cn.Open "Provider=MSDASQL.1;Persist Security Info=False;" & _
  5.       "Data Source=localhost;Initial Catalog=testdb"
  7. Set rs = New ADODB.Recordset
  8. rs.Open "Select * from album", cn, adOpenKeyset, adLockOptimistic
  10. Set mstream = New ADODB.Stream
  11. mstream.Type = adTypeBinary
  12. mstream.Open
  13. mstream.LoadFromFile "C:\Users\Chris\Desktop\sample.jpg"
  14. rs.Fields("picture").Value = mstream.Read
  15. rs.Update
  17. rs.Close
  18. cn.Close
  20. End Sub
My general declarations:

Expand|Select|Wrap|Line Numbers
  1. Dim cn As ADODB.Connection
  2. Dim rs As ADODB.Recordset
  3. 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("picture").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.
Nov 8 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.