Results 1 to 23 of 23

Thread: SQL image

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    SQL image

    i have the following code, it is just a small program to save a picture on an SQL server. i have 2 fields in my SQL talbe on the server. Number and Drawing. number is a char and drawing is set at image.
    VB Code:
    1. Option Explicit
    2. Public Rs As New ADODB.Recordset
    3.  
    4. Private Sub Command1_Click()
    5. With Rs
    6.     .AddNew
    7.     !ArresterNumber = Text1.Text
    8.     !Drawing = Image1
    9.     .Update
    10. End With
    11. End Sub
    12.  
    13. Private Sub Form_Load()
    14. Call makeConnection
    15.  
    16. Dim sql As String
    17. sql = "SELECT * FROM Drawings"
    18. Rs.Open sql, DBConn, adOpenDynamic, adLockOptimistic
    19. End Sub
    20.  
    21. Public Sub Eraser()
    22. Rs.Close
    23. Set Rs = Nothing
    24. End Sub
    i get an error that says type mismatch and the debugger points to
    !Drawing = Image1
    how do isave the image to the SQL Server.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  2. #2
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    I think it will help you...
    Attached Files Attached Files
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    ok thanx, only one problem, i can only read english so the comments don't help me very much, is there any way that you can write them in english?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,954
    Two words: GetChunk and AppendChunk (commonly/affectionatly called GeChunks and BlowChunks in our office). You have to break the image down into a byte array and then AppendChunk the array to the field.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    Dubya007,

    Sorry... I thought comments was in English...


    Here is the same in English...

    []s

    JL
    Attached Files Attached Files
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    it's ok i changed it as necessary and it works, i just need to step through it so that i can understand what it is doing. i need to find a way to load picture from the DB to a pictur box. is that what this does?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  7. #7
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    Dubya,

    I'm so happy it helped you!

    I'm without a SQL connection right now, so I can't help you with another example...

    If I'm right (and I'm not so sure ), if you put something like:

    image1.image = rs!Image

    It can work... (as I said, I'm not sure...)

    []s

    JL
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    hey techgnome would that getchunk and appendchunk work the other way to put a picture off the Db into a vb form?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  9. #9
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    Dubya,

    I couldn't download it cos FireWall rules here...

    so here's the url for a good example...

    http://www.freevbcode.com/code/image.zip Loading/Saving Images to Database: Demo Application
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    ok i downloaded it and it works fine but i have to do that from an SQL Server.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  11. #11
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    As I said, I couldn't download it...

    I think, that uses Access. Is it ?

    I guess the way for load the image from DB is the same...

    As it has an .exe attached, my FW doesn't allow me to download it...

    Could you please, attach it here (w/o the exe), so I can take a look and, maybe, help you to finish your work...

    JL
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    i donno if that one will work or not, there isn't an exe file in there though.
    Attached Files Attached Files
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  13. #13
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    Not the mine one... the other one... (Which I put the link... )
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    sorry.
    Attached Files Attached Files
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  15. #15
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,954
    Originally posted by Dubya007
    hey techgnome would that getchunk and appendchunk work the other way to put a picture off the Db into a vb form?

    GetChunk - gets a chunk of binary data out of the recordset - it comeso ut as a byte array - which can then be saved to a file and used to loadPricture into the pic box.

    AppendChunk - used to append binary chunks into the recordset.

    In short GetChunk gets the data out of the DB and AppendChunk puts it back.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    so all i have to do really is find the picture on the DB. then break it into "chunks" using getchunks and then in my form put it back together again using appendchunks
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    how do you use each of those? like what is the syntax?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    Right now i have the following code. i can put images on the server now with this code but i need to know how to pull them off.
    This puts an image on the server.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim mystream As ADODB.Stream
    3. Set mystream = New ADODB.Stream
    4. mystream.Type = adTypeBinary
    5. mystream.Open
    6. mystream.LoadFromFile "H:\SAMDrawing\MountingW2Nameplates.Bmp"
    7. With Rs
    8.     .AddNew
    9.     !ArresterNumber = Text1.Text
    10.     !Drawing = mystream.Read
    11.     .Update
    12. End With
    13. MsgBox "UPDATED AND WORKED"
    14. mystream.Close
    15. Set mystream = Nothing
    16. End Sub
    This one is my attempt at loading a picture from the DB into a picture box. this isn't done yet this as far as i have gotten.
    VB Code:
    1. Private Sub Command2_Click()
    2. Dim sql As String
    3. ArrestNum = InputBox("Enter Arrester Number", "Arrester number")
    4. sql = "SELECT * FROM Drawings WHERE ArresterNumber = '" & ArrestNum & "'"
    5.  
    6. Dim mstream As ADODB.Stream
    7. Set mstream = New ADODB.Stream
    8.  
    9. mstream.Type = adTypeBinary
    10. mstream.Open
    11.  
    12. mstream.Write Rs.Fields(1).Value
    13. mstream.SaveToFile "H:\testlogo.jpg", adSaveCreateOverWrite
    14.  
    15. mstream.Close
    16. Set mstream = Nothing
    17.  
    18. End Sub
    i'm not sure where to go from here. any pointers towards the right direction?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  19. #19
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    Dubya,

    If you take a look in "image.zip", there's a sub/function (I don't remember which) called LoadImage (or something like that) where the image is saved in a .bin file and then it gives a GetChunk into a PictureBox...


    This example gives you the both save to/load from a DB... It's full complete...

    I'm so sorry to say you what I'll say, but...

    You need to "learn" to read the codes, It's the better way to learn every new things, I'm sure that the answers are in the "Image.zip" (that link I post, remember ?)...

    []s

    JL
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    no don't worry about saying it. i already knew that, i'm just not a very expierenced programmer. as far as schooling goes i only have had an introductory course in VB, we never learned classes or ADO or DAO or anything beyond the elementary things. most of the thinngs that i understand in VB i have learned on my own from the internet. so when i look @ code i understand some of it but some of i do not. i do not want to get people upset At me so i don't want to ask too much of them but i feel like some times i do. the only reason why i do ask is because i want to learn so that i can do my job more effiently. i will look at the sub/function of the program that you gave to me and step through it to try and learn what to do. thanx for all of your help, you've helped me a whole lot, this forum is a very big help.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  21. #21
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    Dubya,

    I'm glad you understand my reasons...

    So as I answered before, that sub/function saves the image on disk, then, puts it on a PictureBox. It's simple, although it doesn't looks like...

    And yes, I agree you, this forum is GREAT!

    []s

    JL
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  22. #22
    Banned
    Join Date
    Jul 2003
    Location
    New delhi
    Posts
    143
    To save a image in a datbase thorugh the ado


    u can use Appendchunk and getchunck

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    i have stepped through the program and it is still seeming to be complicated to me. sorry. i did find a program on the internet that i had to build(actually code). but i understand it, a lot better than other things i have seem in this capacity, the only thing now i am trying to do is be able to select which picture to pull off the DB.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width