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

What is use of hashtable in c#?

679


What is the use of protected in c#?

720


What is a hash table c#?

667


Can you access a hidden base class method in the derived class?

716


How is the syntax written to inherit from a class in C#?Give an example ?

819


What is the use of base keyword? Tell me a practical example for base keyword’s usage?

740


What is Inheritance in C#?

827


What are the differences between a class and a struct?

728


Explain about generics in c#.net?

757


How Do You Convert A Value-type To A Reference-type?

725


Does c# have its own class library?

749


What is the difference between returning iqueryable vs ienumerable?

723


How can we set the class to be inherited, but prevent the method from being over-ridden?

712


what is the scope of anonymous type ?

794


What is lock in c#?

686