468,777 Members | 2,367 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,777 developers. It's quick & easy.

c#.net save image in database

In my project of desktop application using c#.net save image in database during registration of student But it is not mandatory.Without Browse the image i click on insert button it gives error "Empty path name is not legal".

Expand|Select|Wrap|Line Numbers
  1. con.ConnectionString = "Data Source=XPO3;Initial Catalog=Imsapplication;Integrated Security=True";
  2.            con.Open();
  3.            //Cryclass cc = new Cryclass();
  4.            string filepath = textBox2.Text;
  5.            FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
  6.            BinaryReader br = new BinaryReader(fs);
  7.            byte[] photo = br.ReadBytes((int)fs.Length);
  10.            br.Close();
  11.            fs.Close();
How to resolve it using NullReferenceException
Jul 12 '08 #1
1 2621
hi ranjana,
i got the code in VB.net 2003 , it is working fine .

imgstyle is Picture Box

Dim msImage As New MemoryStream
dim strSQL as string

imgStyle.Image.Save(msImage, imgStyle.Image.RawFormat)

Dim arrImage() As Byte = msImage.GetBuffer
dim cmd as sqlcommand

strSQL = "INSERT INTO tblDesignDetails (imgDesign) VALUES ( @Picture )"

cmd = New SqlCommand(strSQL, Cn)
cmd.Parameters.Add(New SqlParameter("@Picture", SqlDbType.Image)).Value = arrImage

[removed email]

Jul 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Sam Martin | last post: by
2 posts views Thread by Corobori | last post: by
9 posts views Thread by DapDap | last post: by
1 post views Thread by Ishtiaque Ahmed Memon | last post: by
3 posts views Thread by =?Utf-8?B?Um9nZWxpbw==?= | last post: by
4 posts views Thread by Logician | last post: by
1 post views Thread by CARIGAR | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.