Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 18th, 2005, 11:12 PM
Authorized User
 
Join Date: Feb 2005
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ashokparchuri Send a message via Yahoo to ashokparchuri
Default disoplaying number of rows.

hi.
   the stored procedures in my databse are designed in a way that if anything goes wrong it retuns an error message.

   in asp i think we can get the message into an variable using "err".

    i want to get thease error message into variable and display the error.please tell me how to do that.


  thanks in advance-Ashok Parchuri.
 
Old April 20th, 2005, 07:43 AM
Authorized User
 
Join Date: May 2004
Posts: 83
Thanks: 0
Thanked 1 Time in 1 Post
Default

Dear ashokparchuri,

Handling with errors in C# .NET is different than VB or ASP. C# uses what are called

Exceptions to handle errors. Specifically, the mechanism used is the try, catch and

finally blocks.

If you expect a portion of code to run into some sort of error, you enclose that code in a try block. Immidiately following the try block, you write a catch block that catches any thrown exceptions. Finally, following the catch block, you write finally block. It contains code that you want to be executed whether or not an exception is thrown (error is raised, in old VB terminology). Here is the general syntax:

Code:
try {
  //code that can throw exception goes here...
}
catch(Exception ex) {
  MessageBox.Show(ex.Message, "Error");
  //code to handle the exception goes here...
}
finally {
  //code that you want to be executed whether
  //or not an exception is thrown goes here...
}
If you prefer you can omit the finally block or the catch block. But at least one of them has to

be there immidiately following the try block.

I hope this would help. But for a complete coverage of error handling in C# you should consult

a good book, such as C# Step By Step (Microsoft Press) or C# .NET Unleashed (SAMS Publishers).

ejan
 
Old April 21st, 2005, 04:28 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Ashok,

I would like to make some clarifications on your question.

 
Quote:
quote:if anything goes wrong it retuns an error message.
Quote:
What exactly do u mean by "it returns" do you throw the error using "RAISERROR" or do you return it as a return parameter.

if you are throwing an error, the solution suggested by ejan is going to work. Otherwise you need to get the value of the return parameter from your code and display it accordingly.


Regards
Ganesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of table rows to a variable Paula222 Access VBA 2 February 7th, 2006 09:33 AM
total number of rows in a recordset lian_a Classic ASP Basics 2 February 8th, 2005 08:13 AM
count the number of rows in the table crmpicco Javascript How-To 4 February 2nd, 2005 12:58 AM
Autofill in unknown number of rows ashu_gupta75 Excel VBA 2 August 9th, 2004 06:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.