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

can't find error in code

Lee
The following code generates the error "...not all code paths return a value" but I can't find the problem. I have tried putting "return;" or "return 0;" just after the close of the "if" statement with no luc

protected void sGetError(SqlException oException, SqlConnection db

int i
sError = ""
if (db != null)

for (i = 0; i < oException.Errors.Count - 1; i++

sError = sError + oException.Errors[i].ToString() + "/n"


Jul 21 '05 #1
5 1430
Lee:

It's running fine for me, the only thing I changed was the second line to
string sError = string.Empty;

(b/c sError is declared outside of this function).
"Lee" <wl*****@nospam.com> wrote in message
news:E7**********************************@microsof t.com...
The following code generates the error "...not all code paths return a value" but I can't find the problem. I have tried putting "return;" or
"return 0;" just after the close of the "if" statement with no luck
protected void sGetError(SqlException oException, SqlConnection db)
{
int i;
sError = "";
if (db != null)
{
for (i = 0; i < oException.Errors.Count - 1; i++)
{
sError = sError + oException.Errors[i].ToString() + "/n";
}
}
}

Jul 21 '05 #2
You didn't declare a type for sError. This method has no return!

protected void sGetError(SqlException oException, SqlConnection db)
{
int i;
string sError = "";
if (db != null)
{
for (i = 0; i < oException.Errors.Count - 1; i++)
{
sError = sError + oException.Errors[i].ToString() + "/n";
}
}
}
HTH;
Eric Cadwell
http://www.origincontrols.com
Jul 21 '05 #3
Wierd, maybe the signature should read:

protected string sGetError(SqlException oException, SqlConnection db)
{
string sError = string.Empty;
... //build the string

return sError;
}

instead of declaring sError outside the function.

-Eric
Jul 21 '05 #4
Eric:

I'm not following you. I took Lee's code and pasted it into a C# project
and it compiled except for that fact that sError wasn't declared. Once it
was, it compiled fine. However, the signature is void, hence it has no
return type so I'm not sure I understand your point.

Bill
"Eric Cadwell" <ec******@ns.insight.com> wrote in message
news:uW**************@TK2MSFTNGP10.phx.gbl...
You didn't declare a type for sError. This method has no return!

protected void sGetError(SqlException oException, SqlConnection db)
{
int i;
string sError = "";
if (db != null)
{
for (i = 0; i < oException.Errors.Count - 1; i++)
{
sError = sError + oException.Errors[i].ToString() + "/n";
}
}
}
HTH;
Eric Cadwell
http://www.origincontrols.com

Jul 21 '05 #5
Yes, I found the same thing, but it never occurred to me that he had
declared sError outside the function (as you noted).
I'm just confused how he got that error message from a void function?

-Eric
Jul 21 '05 #6

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

Similar topics

2
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an...
3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
7
by: a s i l b a . p t | last post by:
Can someone please explain why the following code raises error 2450?... Note: frmTest is a simple form with code behind form so it can be instantiated through the form's class module. Public...
14
by: Stegano | last post by:
I am learning C Programming after working with Java for 5 years. I want to know where can I find the source files for C language itself. For example strcat is a function, which concatenates two...
7
by: Yongsub Eric Shin | last post by:
Hi. I'm just a beginner in ASP.Net. I started writing codes and I keep on getting this Runtime Error page, where it says "Description: An application error occurred on the server. The current...
0
by: dbuchanan | last post by:
Hello, Why can't my application recognize or find the data layer. These are the design-time and runtime errors I receive. \\ "One or more errors encountered while loading the designer. The...
54
by: MLH | last post by:
I use A97 and do not always insert line numbers while writing procedures. I find it necessary to go back and add them later to aid in debugging. Nearly 3 years ago, something was mentioned in...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
kcdoell
by: kcdoell | last post by:
Hello: I have the following afterupdate event: Private Sub GWP_AfterUpdate() 'Updates the Total calculation in the control "SumGWP" on the quick reference 'table that is located on the form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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
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.