Prafulla Choudhary

Prafulla Choudhary

  • NA
  • 89
  • 86.7k

How to store image in Sql Server Database using C# ?

Jul 5 2013 2:22 AM
Dear All 

I am try to convert image in byte then insert it into Database using C#.Below is my code .........



public byte[] getImageData(string strFleNm)
        {
            byte[] ImgData = null;

            FileInfo fileinfo = new FileInfo(strFleNm);
            long imagefilelenght = strFleNm.Length;
            FileStream Fs = new FileStream(strFleNm, FileMode.Open, FileAccess.Read);
            BinaryReader Br = new BinaryReader(Fs);
            ImgData = Br.ReadBytes((int)imagefilelenght);
            return ImgData;
       }

but its give error,Error is like Could not find image .....................

Answers (5)