Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. insert /retrieve text file into/from MySQL

insert /retrieve text file into/from MySQL

Scheduled Pinned Locked Moved Database
mysqlquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kd8341
    wrote on last edited by
    #1

    I have a sample code of insert/retrieve binary file into/from MySQL, it uses FileStream to implement the function. Seems FileStream doesn't work for text file. Can anybody tell what function should I use to retrieve text file from MySQL? Or if you could suggest a sampel code, that will be very helpful. Thanks!

    D 1 Reply Last reply
    0
    • K kd8341

      I have a sample code of insert/retrieve binary file into/from MySQL, it uses FileStream to implement the function. Seems FileStream doesn't work for text file. Can anybody tell what function should I use to retrieve text file from MySQL? Or if you could suggest a sampel code, that will be very helpful. Thanks!

      D Offline
      D Offline
      David Salter
      wrote on last edited by
      #2

      I don't know why a FileStream wouldn't work for text data but would for binary. Can you post your code that doesn't work so we can have a look?


      Affordable and reliable hosting? Click here!

      K 2 Replies Last reply
      0
      • D David Salter

        I don't know why a FileStream wouldn't work for text data but would for binary. Can you post your code that doesn't work so we can have a look?


        Affordable and reliable hosting? Click here!

        K Offline
        K Offline
        kd8341
        wrote on last edited by
        #3

        Hi, Davey: Thanks for your response. Here are my code for text file: String * NCFILE_NAME = "test10.nc"; FileStream * tfs = new FileStream(NCFILE_NAME, FileMode::Open, FileAccess::Read); Char ncbuffer[] = new Char[(int)tfs->Length]; tfs->Read(ncbuffer, 0, ncbuffer->Length); My intention is to read the text from "test10.nc" and write to Char Array ncbuffer[], but tfs->Read(ncbuffer, 0, ncbuffer->Length); cause the error like this: cannot convert parameter 1 from '__wchar_t __gc[]' to 'unsigned char __gc[]' When I did exactly the same for binary file, and define as: FileStream* fs = new FileStream(FILE_NAME, FileMode::Open, FileAccess::Read); Byte buffer[] = new Byte[(int)fs->Length]; fs->Read(buffer,0,buffer->Length); String* extension = "jpg"; // for image file It works fine. So I guess maybe I should use something other than FileStream. But what is it? Could you please give me some ideas about this?

        1 Reply Last reply
        0
        • D David Salter

          I don't know why a FileStream wouldn't work for text data but would for binary. Can you post your code that doesn't work so we can have a look?


          Affordable and reliable hosting? Click here!

          K Offline
          K Offline
          kd8341
          wrote on last edited by
          #4

          Hi, Davey: Thanks for your response. Here are my code for text file: String * NCFILE_NAME = "test10.nc"; FileStream * tfs = new FileStream(NCFILE_NAME, FileMode::Open, FileAccess::Read); Char ncbuffer[] = new Char[(int)tfs->Length]; tfs->Read(ncbuffer, 0, ncbuffer->Length); My intention is to read the text from "test10.nc" and write to Char Array ncbuffer[], but tfs->Read(ncbuffer, 0, ncbuffer->Length); cause the error like this: cannot convert parameter 1 from '__wchar_t __gc[]' to 'unsigned char __gc[]' When I did exactly the same for binary file, and define as: FileStream* fs = new FileStream(FILE_NAME, FileMode::Open, FileAccess::Read); Byte buffer[] = new Byte[(int)fs->Length]; fs->Read(buffer,0,buffer->Length); String* extension = "jpg"; // for image file It works fine. So I guess maybe I should use something other than FileStream. But what is it? Could you please give me some ideas about this? Regards, Kevin

          D 1 Reply Last reply
          0
          • K kd8341

            Hi, Davey: Thanks for your response. Here are my code for text file: String * NCFILE_NAME = "test10.nc"; FileStream * tfs = new FileStream(NCFILE_NAME, FileMode::Open, FileAccess::Read); Char ncbuffer[] = new Char[(int)tfs->Length]; tfs->Read(ncbuffer, 0, ncbuffer->Length); My intention is to read the text from "test10.nc" and write to Char Array ncbuffer[], but tfs->Read(ncbuffer, 0, ncbuffer->Length); cause the error like this: cannot convert parameter 1 from '__wchar_t __gc[]' to 'unsigned char __gc[]' When I did exactly the same for binary file, and define as: FileStream* fs = new FileStream(FILE_NAME, FileMode::Open, FileAccess::Read); Byte buffer[] = new Byte[(int)fs->Length]; fs->Read(buffer,0,buffer->Length); String* extension = "jpg"; // for image file It works fine. So I guess maybe I should use something other than FileStream. But what is it? Could you please give me some ideas about this? Regards, Kevin

            D Offline
            D Offline
            David Salter
            wrote on last edited by
            #5

            Always read the data into a Byte[] rather than a Char[] and it will work for both binary and text files. You shouldn't really need to read it into a char[].


            Database FAQ

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups