Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

sqlite - Converting to Byte Array after reading a BLOB from SQL in C#

I need to read a BLOB and store it in a byte[], before going forward with Deserializing;

Consider:

 //Reading the Database with DataAdapterInstance.Fill(DataSet);
     DataTable dt = DataSet.Tables[0];
    foreach (DataRow row in dt.Rows)
    {
    byte[] BinDate = Byte.Parse(row["Date"].ToString()); // convert successfully to byte[]

    }

I need help in this C# statement, as I am not able to convert an object type into a byte[]. Note, "Date" field in the table is a blob and not of type Date;

Help appreciated; Soham

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just cast the value to a byte array:

byte[] binDate = (byte[])row["Date"];

A blob in the database maps to a byte array in .NET, so the database driver have already done that conversion for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...