Results 1 to 13 of 13

Thread: Read VarBinary in SQL Server

  1. #1

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Question Read VarBinary in SQL Server

    Hi guys,

    There's a VarBinary field in the SQL Server database i need to convert to text.
    The varbinary field is a document template from Microsoft word.
    Is there a way to do this using VB6?

    TIA

    -zynder

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Read VarBinary in SQL Server

    You can try ALTER TABLE
    Code:
    ALTER TABLE TableName ALTER COLUMN ColumnName NVARCHAR(20)
    'of course (20) is just an example.   Use how ever many characters you need
    Execute using the command object like you would any other action query.

    I have nothing against which to test this, but it should work.

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Read VarBinary in SQL Server

    Don't do what Hack suggested..... (Sorry Hack) it will break the field and the data stored in it. There are examples of retriving binary data from SQL Server in these forums. Varbainary will be have the same as an image (you are storing the bytes not the actual word in there). Search for saving and retirving an image to SQL Server.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Read VarBinary in SQL Server

    Thanks for the input. I've search the VB6 section I haven't found one. Can you give me some links?

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Read VarBinary in SQL Server

    Did you even search I found this is about 30 seconds:

    http://www.vbforums.com/showthread.php?t=335207
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Read VarBinary in SQL Server

    @Gary

    The link is for storing. What i need is retrieving the string in varbinary data type.

  7. #7
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Read VarBinary in SQL Server

    Look futer there is a link in there for both storing and retrieving.

    if you can't figure it out from there look here:
    http://www.vbforums.com/showthread.php?t=346752

    same person RB has this. It is even in his sig.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Read VarBinary in SQL Server

    Thanks for the help. Sorry I didn't see the links on the siggy. I will let you know if it works.

  9. #9

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Read VarBinary in SQL Server

    I tested the code. I haven't made it to work using richtextbox as its output. The link posted is an example of extracting picture. Mine is a word document. There's probably a modification i need to make for it to work i'm still figuring it out.

  10. #10

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Read VarBinary in SQL Server

    I'm stumped with this. Any direct link to convert varBinary data type from SQL Server 2005 to text or put it in a richtextbox?

  11. #11
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Read VarBinary in SQL Server

    Read the data as shown.. Save to disk as a temp file with the extention you want (.doc,.rtf,....). open the file into your richtextbox
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  12. #12

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Read VarBinary in SQL Server

    Ok thanks Gary I will try again.

  13. #13

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Read VarBinary in SQL Server

    I don't get the part with image size. I don't have a image size field on the database. How do i get around with this?

    vb Code:
    1. ' Copy the data into the file.
    2.         file_length = adoRST.Fields("IMAGE_SIZE")
    3.        
    4.         num_blocks = file_length / BLOCK_SIZE
    5.         left_over = file_length Mod BLOCK_SIZE

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