By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,497 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,497 IT Pros & Developers. It's quick & easy.

c#.net save image in database

ranjana1980
P: 15
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);
  8.  
  9.  
  10.            br.Close();
  11.            fs.Close();
How to resolve it using NullReferenceException
Jul 12 '08 #1
Share this Question
Share on Google+
1 Reply


P: 50
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

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

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

[removed email]

bye.
ganesh
Jul 13 '08 #2

Post your reply

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