Hi, I M WORKING ON Tiers application i saved picture may be its right way or wrong way but after saving image in Sql server Database workthroug n_tiers c# windows application i can't get back Image plz some one help me here is my some code for saving but i don't have retriving code check my code where i m wrong and plz send me some one code for retrieving code too.
this code of function i wrote on my DataAccessLayer.
public int insertdata(BO.Person person)
{
SqlConnection con=new SqlConnection(connectionstring);
try
{
con.Open();
command = new SqlCommand("sp_Insertdatavalues", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@ID", person.ID);
command.Parameters.AddWithValue("@name",person.Name);
command.Parameters.AddWithValue("@dates", person.UserDate);
command.Parameters.AddWithValue("@address", person.Address);
command.Parameters.AddWithValue("@age", person.Age);
command.Parameters.AddWithValue("@gender", person.Gender);
command.Parameters.AddWithValue("@dateofbirth", person.Dateofbirth);
command.Parameters.AddWithValue("@img", person.Image);
return command.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
command.Dispose();
con.Close();
con.Dispose();
}
}
=====================================================================================
this code i wrote on btnbrowpic to take picture
private void btnbrowspic_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "JPG Files(*.jpg)|*.jpg|GIF Files(*gif)|*gif|ALL Files(*.*)|*.*";
dlg.Title = "SELECT PICTURE";
if (dlg.ShowDialog() == DialogResult.OK)
{
imgloc = dlg.FileName.ToString();
pictureBox1.ImageLocation = imgloc;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
=============================================================================================
and this code i wrote on btnsave_click event
private void button1_Click(object sender, EventArgs e)
{
byte[] imagebt = null;
FileStream fs = new FileStream(imgloc, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
imagebt = br.ReadBytes((int)fs.Length);
BO.Person person = new BO.Person();
person.ID = Convert.ToInt32(textBox1.Text);
person.Name = textBox2.Text;
person.UserDate = dateTimePicker1.Value.Date;
person.Address = textBox3.Text;
person.Age = Convert.ToInt32(textBox4.Text);
person.Dateofbirth = dateTimePicker2.Value.Date;
person.Gender = Gender;
int i = BitConverter.ToInt32(imagebt, 0);
person.Image = BitConverter.GetBytes(i);
BAL.BALPerson pBAL = new BAL.BALPerson();
pBAL.insertdata(person);
}
plz some one check and give me image retriving code too i will be Gratfull