How to Retrive PDF Binary data from sqlserver
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How to Retrive PDF Binary data from sqlserver

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    How to Retrive PDF Binary data from sqlserver

    Dear All,

    How to retrive PDF Binary data from sqlserver and save to PDF file using VC++ ?

    our code is:
    qry="select document from emptable where empno=1"//document field is image datatype
    crs->Open(CRecordset::snapshot,qry,CRecordset::readOnly|CRecordset::executeDirect);

    while(!crs->IsEOF())
    {
    crs->GetFieldValue("document",strDocument);

    }
    we have retrive binary data using CString but when we write this data into a PDF file it is NOT working.

    we think the problem is CString So without CString and GetFieldValue() how can we retrive data?
    Please give to us your suggestions.

    Thank you,
    medwrite.

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,388

    Re: How to Retrive PDF Binary data from sqlserver

    Why don't you use the overloaded CRecordset method
    Code:
    void GetFieldValue( LPCTSTR lpszName, CDBVariant& varValue, short nFieldType = DEFAULT_FIELD_TYPE );
    throw( CDBException, CMemoryException );
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2012
    Posts
    2

    Re: How to Retrive PDF Binary data from sqlserver

    Thank you for reply,

    we have do as per your suggestion

    GetFieldValue( LPCTSTR lpszName, CDBVariant& varValue, short nFieldType = DEFAULT_FIELD_TYPE );

    CLongBinary* binarydata = varValue->m_pbinary;

    But how to write a pdf file using this binary data ?
    Please give to us your suggestions.

    Thank you ,
    Medwrite.

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,388

    Re: How to Retrive PDF Binary data from sqlserver

    Quote Originally Posted by medwrite View Post
    ... we have do as per your suggestion

    GetFieldValue( LPCTSTR lpszName, CDBVariant& varValue, short nFieldType = DEFAULT_FIELD_TYPE );

    CLongBinary* binarydata = varValue->m_pbinary;

    But how to write a pdf file using this binary data ?
    Please give to us your suggestions.
    Sorry, but I have no idea what the relationship is between "pdf file" and some binary data read from SQL Server database.
    What was the data saved as binary in database and what did it have to do with the .pdf file?
    Victor Nijegorodov

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,972

    Re: How to Retrive PDF Binary data from sqlserver

    Quote Originally Posted by medwrite View Post
    CLongBinary* binarydata = varValue->m_pbinary;

    But how to write a pdf file using this binary data ?
    Please give to us your suggestions.
    I believe, the answer is pretty obvious. Did you bother to check CLongBinary documentation. HGLOBAL m_hData member contains data bytes handle, DWORD m_dwDataLength member contains bytes count. What is the problem here? You use GlobalLock function to access actual data bytes. And don't forget to unlock it later.

    And I hope you know how to write memory buffer of known size to file.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center