473,406 Members | 2,352 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,406 software developers and data experts.

Problems with Images and SQL !


Hi!

This is the errorcode I get when I try to insert some new data inot my
SQL DB.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Line 125: Dim connectionString As String =
"server='localhost'; user id='sa'; password='xxxxx'; Database='xxxxx'"
Line 126: Dim ImageStream As Stream =
FotoFile.PostedFile.InputStream
Line 127: Dim byteData(FotoFile.PostedFile.ContentLength) As
Byte
The problem is on Line 126.

What´s the problem? Can´t find it out myself.
Is there anyone who has any ideas ?

OM "Myggan"

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
4 1048
First check to see if the FotoFile is not null

Attaching some code that i use to upload files

HttpFileCollection myFiles = Request.Files;
CodePlayDB myCode = new CodePlayDB();
if(myFiles.Count != 0)
{
try
{
HttpPostedFile myFile = myFiles[0];
if( myFile != null)
{
if(myFile.FileName != "")
{
try
{
int fileLength = myFile.ContentLength;
byte[] fileData = new byte[fileLength];
Stream myStream = myFile.InputStream;
myStream.Read(fileData, 0, fileLength);

string fileContentType = myFile.ContentType;
myCode.AddImageToDB(fileContentType, fileData);
}
catch (Exception ex1)
{
Label1.Text = "Error uploading file '" + myFile.FileName +
"'<br>Error: " + ex1.ToString();
}
}
}
}
catch (Exception ex)
{
Label1.Text = "Error uploading file '" +
fileUpload1.PostedFile.FileName + "'<br>Error: " + ex.ToString();
}
}
else
Label1.Text = "Please enter a valid file";
}

--
Regards,

HD

"Ola Myrgart" <pb****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

Hi!

This is the errorcode I get when I try to insert some new data inot my
SQL DB.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Line 125: Dim connectionString As String =
"server='localhost'; user id='sa'; password='xxxxx'; Database='xxxxx'"
Line 126: Dim ImageStream As Stream =
FotoFile.PostedFile.InputStream
Line 127: Dim byteData(FotoFile.PostedFile.ContentLength) As
Byte
The problem is on Line 126.

What´s the problem? Can´t find it out myself.
Is there anyone who has any ideas ?

OM "Myggan"

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
Hi!

Thank you for your answer. Maybe you have some code in VB.Net for the
same application.

Regards

OM "Myggan"

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
unfortunately i dont have any VB code.... but you can almost do a line by
line conversion very easily...

something similar to your code
http://www.aspalliance.com/articleVi...x?aId=138&pId=

HTH
--
Regards,

HD

"Ola Myrgart" <pb****@hotmail.com> wrote in message
news:OO****************@TK2MSFTNGP11.phx.gbl...
Hi!

Thank you for your answer. Maybe you have some code in VB.Net for the
same application.

Regards

OM "Myggan"

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4
The NullReferenceException means that one or more objects you referred to in
the offending line of code are null. In this case, the offending line of
code is:
Dim ImageStream As Stream = FotoFile.PostedFile.InputStream
The left-hand side of the assignment can't be the problem, because all it
does is declare a variable. On the right-hand side, you are referring to
three distinct objects:

FotoFile
FotoFile.PostedFile
FotoFile.PostedFile.InputStream

Since every HttpPostedFile class has an InputStream property, the third can
be eliminated immediately, leaving:

FotoFile
FotoFile.PostedFile

I will assume that "FotoFile" is an HtmlInputFile Control. Assuming that the
Control was not added dynamically, it is unlikely that this is null,
leaving:

FotoFile.PostedFile

Did you check to see whether any file was uploaded using that Control?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Ola Myrgart" <pb****@hotmail.com> wrote in message
news:#L**************@TK2MSFTNGP12.phx.gbl...
Hi!

This is the errorcode I get when I try to insert some new data inot my
SQL DB.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Line 125: Dim connectionString As String =
"server='localhost'; user id='sa'; password='xxxxx'; Database='xxxxx'"
Line 126: Dim ImageStream As Stream =
FotoFile.PostedFile.InputStream
Line 127: Dim byteData(FotoFile.PostedFile.ContentLength) As
Byte
The problem is on Line 126.

What´s the problem? Can´t find it out myself.
Is there anyone who has any ideas ?

OM "Myggan"

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nigel Gomm | last post by:
i have a problem with Mac browsers. As can be seen from the following HTML fragment i have some images that should, when clicked, open up a <div>. This works fine on all window's browsers (that...
13
by: murali | last post by:
Hello everyone, I used absolute positioning with div tag in my website. The page looks cool as long as someone doesn't try to zoom in by increasing the text size (ctrl++ or thru changing font...
1
by: Zeroeffect | last post by:
Hello! I have a database with alot of embedded images. The reason for having the images embedded is security. My problem is that it works fine on my computer, but not on my clients computer....
3
by: Scott | last post by:
Hello, we are having problems displaying non-aspx files (images, style sheets) since we have upgraded to the 1.1 framework when using a cookieless session (sessionID in the url). Check out...
3
by: John Tacke | last post by:
When developing ASP.NET apps using Microsoft's recommended isolated model (develop on your local iis), there are deployement reference problems because the local website is generally one level deeper...
2
by: BluDog | last post by:
Hi I have a created a custom web control called ImageBrowser, extract is below: <Code> #Region "Properties" Public Property Images() As ImageCollection
3
by: Jeff | last post by:
I've been working on an application for a while now that has been giving me some trouble when it comes to working with a picturebox and memory usage. My company deals with digital imaging, so we...
1
by: baroque Chou | last post by:
Thanks for the help available on msdn, I have succesful done the rewrite job. But there are 2 problems arise: 1.when I try to rewrite the url from say: www.yoursite.com/beverages.aspx to...
0
by: David | last post by:
Hello all. I am trying to implement my first server control and have run into two problems that I cannot solve. I need the assistance of someone with more experience. My goal was to create an...
34
by: aljamala | last post by:
I keep getting this error for the given code region (it actually highlights the line with the body tag): line 42 column 1 - Warning: <trisn't allowed in <bodyelements </head> <body...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.