Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:53:28+00:00 2026-05-23T16:53:28+00:00

please help. I read here some topics, but don’t get answer on my question.

  • 0

please help. I read here some topics, but don’t get answer on my question. I try put image in BLOB type of SQLite DB and then retrive it, but it failed.

So, using
rawDoc = File.ReadAllBytes(openFileDialog.FileName);
i get byte[] rawDoc of some image (or other file). Then

String dbConnection = "Data Source=dbase.s3db";
SQLiteConnection cnn = new SQLiteConnection(dbConnection);
cnn.Open();
String sql = String.Format("INSERT INTO registry" +
            "(NameDoc, YearDoc, MonthDoc, DayDoc, RawDoc) VALUES" +
            "('{0}', '{1}', '{2}', '{3}', '{4}')",
            txtNameDoc.Text, numUDYear.Value, numUDD.Value, numUDD.Value, Convert.ToBase64String(rawDoc));

if i try verify rawDoc with that

byte[] imageBytes = Convert.FromBase64String(testRaw);
        MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
        ms.Write(imageBytes, 0, imageBytes.Length);
        pictureBox1.Image = Image.FromStream(ms, true);

I get normal picture. But if i try do that with data from SQLite base with

SQLiteCommand myCommand = new SQLiteCommand(query, cnn);
        SQLiteDataReader myDataReader = myCommand.ExecuteReader();

        string raw = null;
        while (myDataReader.Read())
        {
           raw += myDataReader["RawDoc"].ToString().Trim();

        }

        myDataReader.Close();
byte[] imageBytes = Convert.FromBase64String(raw);
        MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
        ms.Write(imageBytes, 0, imageBytes.Length);

        imageBox imgbox = new imageBox();
        PictureBox picBox = new PictureBox();
        picBox.Image = Image.FromStream(ms, true);
        imgbox.Controls.Add(picBox);
        imgbox.Show();

I get an error: FormatException. Invalid characters in a string Base-64. Why?

thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:53:28+00:00Added an answer on May 23, 2026 at 4:53 pm

    There is no need to convert your byte array to a base 64 string. You’ll just end up using more space for nothing in your database. Additionally, you would then actually have TEXT data in your sqlite database, not a BLOB.

    What you need to do is used SqliteParameters, for example to insert your BLOB, you can do something like this:

    SQLiteCommand command = cnn.CreateCommand();
    command.CommandText = String.Format("INSERT INTO registry" +
            "(NameDoc, YearDoc, MonthDoc, DayDoc, RawDoc) VALUES" +
            "('{0}', '{1}', '{2}', '{3}', @0)",
            txtNameDoc.Text, numUDYear.Value, numUDD.Value, numUDD.Value);
    SQLiteParameter parameter = new Parameter("@0", System.Data.DbType.Binary);
    parameter.Value = rawDoc;
    command.Parameters.Add(parameter);
    command.ExecuteNonQuery();
    

    When you retrieve the BLOB, get it from your SQliteDataReader this way:

    byte[] imageBytes = (System.Byte[])myDataReader["RawDoc"];
    

    EDIT

    To answer you’re comment, I’m guessing that your stream would need to be re-winded. In Any case, this is I’d do it more this way:

        MemoryStream ms = new MemoryStream(imageBytes);
        PictureBox picBox = new PictureBox();
        picBox.Image = Image.FromStream(ms, true);
    

    EDIT 2

    Then I think the problem is with how you retrieve from your DataReader; try something more like this:

        string raw = "";
        while (myDataReader.Read())
           raw = (string)myDataReader["RawDoc"];
    

    This is still probably broken as the loops iterates over all retrieved records, so you’ll end up with the image of the last record retrieved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read about intents in android but here goes my question. I'd like to
Hi guys I was hoping from some help here, please. I have a INSERT
Please help, I am stuck here --- irb> a = line of text\n line
Here is an excellent question and the wonderful tchrist 's answer with 7+24+52 advices&comments
I know that this question is being asked before but I did not get
Please help! I'm really at my wits' end. My program is a little personal
Please help! Background info I have a WPF application which accesses a SQL Server
Please help me with a sanity check. Assuming a many-to-many relationship: Post, PostTagAssoc, Tag
Please help! I couldn't figure it out how to map the following situation: I
Please help us settle the controversy of Nearly everything is an object ( an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.