'Saving image to database

Hi i made a program that saves my drawing to a image on button press, but i need to push it into a MySql database, anyone know how?

this is how my image saving program works(its mostly used to draw signatures).

i will be using the visual studio Microsoft SQL Database.

    public Werkbon()
    {
        InitializeComponent();
    }

    Pen somePen = new Pen(Color.Black, 3.0f); // make a black pen with 3,0 width
    List<Point> currentLine = new List<Point>();
    List<List<Point>> curves = new List<List<Point>>();

    public void panel1_Paint(object sender, PaintEventArgs e)
    {
        using (Pen somePen = new Pen(Color.Black, 3.0f))
        {
            if (currentLine.Count > 1) e.Graphics.DrawCurve(somePen, currentLine.ToArray());
            foreach (List<Point> lp in curves)
                if (lp.Count > 1) e.Graphics.DrawCurve(somePen, lp.ToArray());
        }
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            currentLine.Add(e.Location);
            panel1.Invalidate();
        }
    }//END method

    private void button3_Click(object sender, EventArgs e)
    {
        curves.Clear(); currentLine.Clear(); panel1.Invalidate(); // clear the field
    }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
        if (currentLine.Count > 1) curves.Add(currentLine.ToList());
        currentLine.Clear();
        panel1.Invalidate();
    }

    //database vv

    private void Save_Click_1(object sender, EventArgs e)
    {
        SaveFileDialog save = new SaveFileDialog();
        save.CheckFileExists = false;
        save.CheckPathExists = true;
        save.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; 
         *.jpe; *.jfif; *.png";
        save.InitialDirectory = @"C:\images\";

        DialogResult result = save.ShowDialog();
        if (result == DialogResult.OK)
        {
            Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);

            panel1.DrawToBitmap(bmp, new Rectangle(0, 0, panel1.Width, panel1.Height));

            bmp.Save(save.FileName);

        }
    }
}


Solution 1:[1]

In most cases it is recommended to store images in the file system, and save the path to this file in the database.

So you should be able to keep your existing code to save the file to some configured storage folder, and use a column in the database to store this path. You might also consider storing a relative path, and reference a separate table that has the absolute path to the root folder. But this is mostly helpful when you have huge number of images, and need multiple disks for storage.

The exact instructions for adding a new column, and how to use said column might be out of scope for this question.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JonasH