473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

c#.net save image in database

ranjana1980
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
1 2836
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

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

Similar topics

1
by: Sam Martin | last post by:
Hi all, got a problem when converting a PNG to a JPG using the Image.Save(stream, format) method. When I save the original PNG to a file and open it, it's fine. I then save it to a database,...
2
by: Corobori | last post by:
I am getting an error message "Description: Value cannot be null. Parameter name: encoder" when performing this instruction: frmPicView.pic.Image.Save(ms, frmPicView.pic.Image.RawFormat) Here is...
9
by: DapDap | last post by:
I have manage to open a image into a picture box. But I have problem in Saving it into database SQL Server. How to save the image ??
1
by: Ishtiaque Ahmed Memon | last post by:
Dear All Can anyone tell me how to save an JPEG image in a database table field? Below is the code that I have wrote but it gives an error: System.InvalidCastException Object must implement...
1
by: ankz | last post by:
Hi Guys I have got 3 tables - in Access Database with Student ID as primary Key in all and all tables are linked with 1 to 1 relationship. I have code the everying with manual program to...
1
by: Smita Kashyap | last post by:
Hello to all, Which one is flexible/optimal solution to save uplaoded image. Frist save image at server or from where you're site pages are save in any image folder and save only image name or...
3
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
I'm having the wierdest problem. I'm trying to save images into a SQL 2005 database. the field is just called "IMAGES" and hte data type is "image". here is my code to save //following code...
4
by: Logician | last post by:
I am running on my PC Windows Forms to collect data from websites, including images. I hit a problem with images and javascript, and I would appreciate any help. The current code fails with a...
0
by: hnpatel | last post by:
hello friends, i m making application in vb.NET. i m using MY SQL 5.0 and vs 2005 for this application. Now I want to save image file in sql database. i m using blob datatype of image field. i...
8
by: anandmms | last post by:
Hello friend, my problem is to save more than one fingerprint images in one byte array and then store in database(oracle). i dont know how to solve it. But previously i had did image saving...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.