How to store image file in Sql server database?

Answer Posted / y.s.a.naidu

MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms,
pictureBox1.Image.RawFormat);
byte[] img = ms.GetBuffer();

SqlCommand cmd = new SqlCommand("Insert into
tbl_Image(Images) values(@imgs)", cn);
SqlParameter p1 = new SqlParameter();
p1.ParameterName = "@imgs";
p1.SqlDbType = SqlDbType.Image;
p1.Value = img;
cmd.Parameters.Add(p1);
cn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Image Inserted ....");
cn.Close();

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

You are creating a custom usercontrol, some of the newly created properties are shown in the properties window. How you can hide a new property named theme from the properties window?

494


What are "class access modifiers" in C#?

536


Can a class have multiple constructors c#?

494


Explain what a diffgram, and a good use for one Define diffgram? How it be used?

542


What is interpolation in programming?

486






What is a console device?

480


What is the difference between disposing of () and finalize() methods in c#?

544


Define a manifest in .net?

534


How to override a function in c#?

540


What is reflection in c#?

489


Explain About stateless and state full web service

568


How many types of constructors are there in c#?

465


How can I develop an application that automatically updates itself from the web?

472


What are the Types of configuration files and their differences

547


How many parameters can a method have c#?

483