473,494 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

error handling

hi all
im facing a problem in error handelling.
what im doing is getting the images from the database to my
csharp application form .. now here in some of the records contains
images along with the data where as some as has null value ..
who to trap this please help
thanks for the help..

Nov 17 '05 #1
2 1584
jack wrote:
im facing a problem in error handelling.
what im doing is getting the images from the database to my
csharp application form .. now here in some of the records contains
images along with the data where as some as has null value ..
who to trap this please help


Well, firstly - how are you retrieving the data? Whichever way it is,
there's bound to be something like IsDbNull() for the appropriate
column. (Alternatively, you can get the value and test for it being
DbNull - with "if (value is DbNull)".

You then need to work out what to do with those records, of course.

Jon

Nov 17 '05 #2
Hi,

You have to check for null , if so you have to decide what to do, either
assign null to the variable or just use some predefined image.
Here is some code, it was extracted from a bigger program so it does not
compile, it's just for you to look into it
protected override void Load()
{
//generate a new local name for this file
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "LoadDocument";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@dID", SqlDbType.Int).Value = id;
SqlDataReader reader = DataProvider.ExecuteReader( cmd);
while( reader.Read() )
{
this.comment = "";
this.origname = reader["OrigName"].ToString();
this.dDate = Convert.ToDateTime( reader["dDate"]);

this.name = Guid.NewGuid().ToString() + "." + origname.Substring(
origname.LastIndexOf(".")+1);
physicalname = physicalname + @"\" + name;
ExtracFileFromDB( reader);

}
reader.Close();
}
protected void ExtracFileFromDB( SqlDataReader reader)
{
if ( reader["Data"] != DBNull.Value )
{
FileStream file = new FileStream( physicalname, FileMode.Create);
file.Write( (byte[])reader["Data"], 0,
((byte[])reader["Data"]).GetUpperBound(0)+1 );
file.Close();
}

}

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"jack" <ga**********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
hi all
im facing a problem in error handelling.
what im doing is getting the images from the database to my
csharp application form .. now here in some of the records contains
images along with the data where as some as has null value ..
who to trap this please help
thanks for the help..

Nov 17 '05 #3

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

Similar topics

2
3254
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
12
6642
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
21
4372
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
3
2835
by: Stefan Johansson | last post by:
Hi all I'am moving from Visual Foxpro and have a question regarding "best practice" error handling in vb .net. In VFP I have always used a "central" error handling object in order to have a...
4
1905
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I...
1
9905
by: Metal Dave | last post by:
I do not understand the error handling of SQL Server here. Any error in bulk insert seems to halt the current T-SQL statement entirely, rendering it impossible to log an error. The first statement...
10
2267
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
1
2239
by: pob | last post by:
>From a form I have some code that calls 4 modules frmMain 1 mod 2 mod 3 mod 4 mod If mod 1 experiences an error the error handling works fine within mod 1 and writes out the error to a...
35
3734
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
0
11549
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
0
6989
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
7157
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,...
1
6873
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
7367
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
5453
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,...
1
4889
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...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.