I think the better option to storing image is to convert image to byte[] then store it in Database
Open a File First
byte[] big;
private void button7_Click(object sender, EventArgs e)
{
OpenFD.Title = "Select Files";
OpenFD.Filter = "Jpg|*.jpg|Jpge|*.jpge|Gif|*.gif";
OpenFD.FileName = null;
string fileName;
if (OpenFD.ShowDialog() != DialogResult.Cancel)
{
querybuilder qu = new querybuilder();
fileName = OpenFD.FileName;
Object refmissing = System.Reflection.Missing.Value;
try
{
pictureBox2.Load(fileName);
big = get_image(fileName);
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex.Message.ToString());
}
}
}
get_image function is below
public byte[] get_image(string filePath)
{
FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(stream);
byte[] photo = reader.ReadBytes((int)stream.Length);
reader.Close();
stream.Close();
return photo;
}
And now make sql query
string sqlquery="insert into Tablename(id,image) values(1,@big)";
SqlParameter param = new SqlParameter("@big", SqlDbType.Binary);
param.Value = big;
Note:- Create Sqlcommand self I didn't include it in that solution