Feeds:
Posts
Comments

Archive for September, 2010

During recent debugging of T-SQL stored procedures, I found adding following
code in your catch block will help to point the actual cause of error and make your programming life much easy!

 Begin Try
    Print 'Do Something'
 End Try
 BEGIN CATCH
         ROLLBACK TRANSACTION
         print 'Error Msg: ' + ERROR_MESSAGE()
         print 'Error Procedure: ' + ERROR_PROCEDURE()
         print 'Error Number: ' + convert(varchar(50),ERROR_NUMBER())
         print 'Error Line: ' + convert(varchar(50),ERROR_Line()
   END CATCH

Source : http://msdn.microsoft.com/en-us/library/ms178600.aspx

Read Full Post »

A neat language syntax in C#

isTrue ? thenDoThis : ElseDoThis

bool isBodyHTML=onFileReceived.Attributes["isBodyHTML"].Equals("true")?true:false

Read Full Post »

C# 4.0 now supports using optional parameters with methods, constructors, and indexers (note: VB has supported optional parameters for awhile).

This is how you declare your method to have optional parameter

public Boolean SendMail( string[] toAddresses, string subject, string body,string sender = "bala.singam@hotmail.com",bool isBodyHTML=false)
{
 
try
            {
                MailMessage mailMessage = new MailMessage();
                mailMessage.From =new MailAddress(sender);
                mailMessage.IsBodyHtml = isBodyHTML;

                foreach (string address in toAddresses)
                    mailMessage.To.Add(new MailAddress(address));

                mailMessage.Subject = subject;
                mailMessage.Body = body;

                SmtpClient smtpClient = new SmtpClient();
                smtpClient.Send(mailMessage);

                return true;
            }
            catch (SmtpException ex)
            {
               Console.WriteLine(ex);
                return false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return false;
            }
}

And this is how you call your method with optional parameters/named arguments

//I did't passed sender parameter value
mailer.SendMail(toAddresses:new string[] { "bala.singam@hotmail.com" },subject: "File Received", body:Encoding.UTF8.GetString(msg),isBodyHTML:true);

Source : http://weblogs.asp.net/scottgu/archive/2010/04/02/optional-parameters-and-named-arguments-in-c-4-and-a-cool-scenario-w-asp-net-mvc-2.aspx

Read Full Post »

%d bloggers like this: