Tutorial :How do I extract data from a FoxPro memo field using .NET?



Question:

I'm writing a C# program to get FoxPro database into datatable everything works except the memo field is blank or some strange character. I'm using C# .Net 2.0. I tried the code posted by Jonathan Demarks dated Jan 12. I am able to get the index but i don't know how to use this index to fetch the data from memo file.

Pleaese help me.

Thanks Madhu


Solution:1

I created the below function that converts the object returned by the selection to an array of bytes.

private byte[] ObjectToByteArray(Object obj)  {      if (obj == null)      {          return null;      }        BinaryFormatter bf = new BinaryFormatter();      MemoryStream ms = new MemoryStream();      bf.Serialize(ms, obj);      return ms.ToArray();  }  

Then you are able to display the value.

byte [] dBytes = ConvertObjectToByteArray(dr["profile"]);  System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();  string str = enc.GetString(dBytes);  

You now have the value in a C# native string and can do what you want with it.


Solution:2

Have you tried using the FoxPro OLEDB provider? If the database doesn't use features introduced by VFP8 or 9 (notably database events) you could use the ODBC driver as well.

Are these general fields containing documents or images, or text memos or binary memos? What code are you using to extract the data?


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »