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. General Programming
  3. C#
  4. foxpro general field type and c# byte[]

foxpro general field type and c# byte[]

Scheduled Pinned Locked Moved C#
csharpdata-structureshelpquestionlounge
1 Posts 1 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.
  • M Offline
    M Offline
    mcgahanfl
    wrote on last edited by
    #1

    //The problem is that bytes written to a FoxPro General Field are not being read back in correctly. //This code will write 10 bytes to a general field and then read them back in. When the data is read back it will be incorrect. //Part 1 of 2. Write a byte[] with values 0..9 to a foxpro 'General Field' OleDbConnection oleDbConnection = new OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=c:\blobTest\"); oleDbConnection.Open(); byte[] adtByte = new byte[10]; for(Int16 i = 0; i < 10; i++)//load the array with values 0,1,2,3,4,5,6,7,8,9 adtByte[i] = (byte)i; OleDbCommand command = oleDbConnection.CreateCommand(); command.CommandText = "DELETE FROM image"; //clean up past attempts command.ExecuteNonQuery(); command.CommandText = "INSERT INTO image (image_len, image_val) VALUES (?, ?)"; //foxpro table 'image' has two fields. image_len of type interger and image_val of type general. OleDbParameter p1 = new OleDbParameter("?", OleDbType.Integer); p1.Value = adtByte.Length; command.Parameters.Add(p1); OleDbParameter p2 = new OleDbParameter("?", OleDbType.Binary); p2.Value = adtByte; //write the byte array as type binary - I think this is my problem???? command.Parameters.Add(p2); command.ExecuteNonQuery(); command.Dispose(); //At this point we should have one row in the table and the values should be; // image_len = 10 // image_value = 0123456789 //-------------------------------------------------------------- //Part 2 of 2. Read the row just created back into a pair of variables. OleDbCommand oleDbCommand = new OleDbCommand("Select * from image", oleDbConnection); OleDbDataReader oleDbReader = oleDbCommand.ExecuteReader(); while (oleDbReader.Read()) { object objFieldImage = oleDbReader["image_val"]; byte[] inBytes = (byte[])objFieldImage; object objFieldLen = oleDbReader["image_len"]; int iLen = Convert.ToInt32(objFieldLen); //At this point image_len is 10 as expected. //but inBytes has doubled in size and the value is all wrong. } thanks:^)

    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