0

I want to read a blob to a byte array and show the current byte array in the cmd.

This is my code at the moment:

string connector = @"data source=C:\testfile; Version=3;";

SQLiteConnection connection = new SQLiteConnection(connector);
SQLiteCommand command = new SQLiteCommand(connection);

connection.Open();

command.CommandText = "SELECT file FROM users";

SQLiteDataReader reader = command.ExecuteReader();

while (reader.Read())
{
    int i = 0;

    byte[] bytBLOB = new byte[reader.GetBytes(0, 0, null, 0, int.MaxValue) - 1];
    reader.GetBytes(0, 0, bytBLOB, 0, bytBLOB.Length);
    Console.WriteLine(bytBLOB.ToString());

    i++;    
}

Currently my code doesn't work. It just prints out two lines of (I've got two items in "file"):

System.Byte[]
System.Byte[]

How to get my code working. Reading all relevant posts to blob in c# doesn't help me in this situation. I used this help: blogpost

1 Answer 1

1

.ToString() doesn't work like you expect on a byte[]. You'll need something like:

Console.WriteLine( Encoding.Default.GetString( bytBLOB ) ) ;

assuming the bytes in the blob represent printable characters in the default encoding. If they're random data, you'll need to dump them byte-by-byte.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.