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 are the different types of classes?

476


What is an event in c#?

497


write a C# Program add two matrix ?

572


Why abstract class is not instantiated in c#?

520


What is strongly typed in c#?

496






What is default constructor in c#?

494


What is the difference between finalize() and dispose()?

494


What are assemblies?

539


What is indexer c#?

465


Can properties be static in c#?

544


Can a child class call the constructor of a base class?

543


What is a factory in c#?

474


What are the types of comment in c# with examples?

479


Why do you call it a process? What’s different between process and application in .net, not common computer usage, terminology?

530


Why reflection is used in c#?

492