Good morning Peter,
First of all, please help to check whether I understand the question
rightly or not:
***** PROBLEM DESCRIPTION *****
We used VB6 to store a float array into an OLE Object field of a Access
DB.
VB6: float array -> string (or a byte array) -> OLE Object field of a
Access DB.
Our need is to retrieve the float array from the OLE Object field using
C#.
C#: OLE Object field of the Access DB -> string (or a byte array) -> float
array.
Am I right?
*** PHASE 1. OLE Object field of the Access DB -> string (or a byte array)
***
In order to get the byte array (or the string) from the DB using C#, we
need to use the System.Data.OleDb namespace. Here is an example:
// the connection string of the access database.
string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\db3.mdb";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open(); // open the connection
// the sql command
string query = "SELECT * FROM tblTest";
OleDbCommand cmd = new OleDbCommand(query, conn);
// read the data
while (rdr.Read())
{
byte[] arr;
// the ole object field returns as a byte array.
arr = rdr["ObjValue"] as byte[];
// if you need the string value, we can use Encoding.GetString to
parse the byte array to a string.
string val = System.Text.Encoding.Unicode.GetString(arr);
}
// close the reader and the connection.
rdr.Close();
conn.Close();
The first line of the example sets the connection string of the access
database. If you are using Access 2007, please refer to
http://www.connectionstrings.com/?carrier=access2007, otherwise, see
http://www.connectionstrings.com/?carrier=access.
The code line arr = rdr["ObjValue"] as byte[]; and string val =
System.Text.Encoding.Unicode.GetString(arr); retrieves the value of the
ole
object and put it in a byte array or a string object.
*** PHASE 2. string (or a byte array) -> float array ***
This phase of conversion depends on your algorithm of "float array ->
string (or a byte array)" in VB6. Peter, if you do not mind telling me
your
code of converting a float array to a string in VB6, I'd like to write
some
examples of the reverse conversion for your reference. You may also want
to
read this article:
http://www.codeproject.com/KB/vb/CopyMemory_in_Net.aspx
It demonstrates the equivalent in .NET of various type conversion in VB6.
For example, array <-> string, array <-> array, string <->string.
Is my suggestion above helpful to you? If you have any other questions or
concerns, please DON'T hesitate to tell me.
Regards,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.