Hi I upload image into Picture box convert it into bytes and try to save it into SQLite data base which have blob data type but instead of saving binary of Picture it is showing System.Byte[] in database and not giving any error. this is how it looks like in database
Here is the code i use to save image:
public partial class ImageForm : Form
{
public ImageForm()
{
InitializeComponent();
}
SQLiteConnection sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=False;Compress=True;");
private void button2_Click(object sender, EventArgs e)
{
//To convert immage into bytes
Image img = pictureBox1.Image;
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] dataByte = ms.ToArray();
//Saving into database. .
sqlite_conn.Open();
SQLiteCommand cmd_Insert = new SQLiteCommand("Insert into ForImage(ImageFile) values ('" + dataByte + "')", sqlite_conn);
cmd_Insert.ExecuteNonQuery();
}
// To Show/load Image in Picturebox 1.
private void button1_Click(object sender, EventArgs e)
{
DialogResult = openFileDialog1.ShowDialog();
if (DialogResult == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(openFileDialog1.FileName);
}
}
}
Please tell me what is the problem and how i can resolve it. Thanks in advance
Aucun commentaire:
Enregistrer un commentaire