Wednesday, April 4, 2012

How to Use String Builder in C#..

It is used to build a formatted string.Lets Look at the Example You will get the Clear Idea about it....


            string spaces = "      ";
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("Hello,");
            sb.AppendFormat("<br/>");
            sb.AppendFormat("<br/>{0}",spaces);
            sb.AppendFormat("A new  request is submitted. Details are as follows");
            sb.AppendFormat("<br/>{0}", spaces);
            sb.AppendFormat("<b>Page URL</b>  :  ");
          
            sb.AppendFormat("<br/>{0}", spaces);
            sb.AppendFormat("<b>FirstName</b>  :  ");
          
            sb.AppendFormat("<br/>{0}", spaces);
            sb.AppendFormat("<b>LastName</b>  :  ");
          
            sb.AppendFormat("<br/>{0}", spaces);
            sb.AppendFormat("<b>CompanyName</b>  :  ");
          
            sb.AppendFormat("<br/>{0}", spaces);
            sb.AppendFormat("<b>Phone</b>  :  ");
          
            sb.AppendFormat("<br/>{0}", spaces);
            sb.AppendFormat("<b>Email</b>  :  ");
          
Now If you Print sb in Page you will get Like this...
            Hello,
                     A new  request is submitted. Details are as follows
                     FirstName
                     LastName
                     CompanyName
                     Phone
                     Email

If and Else in SQL.....


CREATE PROCEDURE [dbo].[GetFilterData]
-- Add the parameters for the stored procedure here
@CourseLibraryCategoryID int,
@Search nvarchar(50),
@LanguageTypeId nvarchar(50)
AS
BEGIN
if @CourseLibraryCategoryID!=0
begin
select * from TrainingCourses TC LEFT JOIN TrainingSkins TS ON TC.[SkinID] = TS.[SkinID]   where CourseID in(select CourseID from CourseCategory where CategoryID=@CourseLibraryCategoryID)
end

else if @LanguageTypeId!=''
begin
select * from TrainingCourses TC LEFT JOIN TrainingSkins TS ON TC.[SkinID] = TS.[SkinID] where   TC.[LanguageTypeID]= @LanguageTypeId
        end

else
begin
select * from TrainingCourses TC LEFT JOIN TrainingSkins TS ON TC.[SkinID] = TS.[SkinID] where  TC.[CourseName] Like '%'+@Search + '%'
     end
END