Add Condition in Select Clause

Standard

For example you need to build a query which displays the username and if he administrator or not according to his role. you can use case statment like the following:
note:Assume admin user has the typeID = 1

SELECT *,(SELECT CASE Type WHEN 1 THEN ‘Yes’ ELSE ‘No’ END AS IsAdmin)
From Users

Its syntax like the following:

SELECT CASE –Column Name–
WHEN –Value1– Then –Result1–
WHEN –Value2– Then –Result1–
WHEN –Value3– Then –Result1–
……..
ELSE –Default Result–
END

Create RSS Feed With ASP.NET Framework 4.0

Standard

You can use the name space System.ServiceModel.Syndication in assembly System.ServiceModel which is added by default to new ASP.NET website project based on .net framework 4.0 ( I didn’t try it with .net framework 3.5 ).

Following is the code to view RSS to one channel called MyFeed and has items Hello1, Hello2 and Hello 3

1 – Create new aspx page

2 – Add the following code to its code behind in the page load handler

//Prepare the channel
Uri uri = new Uri(“http://helloworld”);
List<SyndicationItem> items = new List<SyndicationItem>();
for(int i = 0 ; i < 3 ; i ++)
{
         SyndicationItem item = new SyndicationItem();
         item.Title = new TextSyndicationContent(“hello”+ i);
         items.Add(item);
}
SyndicationFeed fe = new SyndicationFeed(“my feed”,”my description”,uri);
fe.Items = items;

//Add the RSS to the response
Response.Clear();
Response.ContentType = “application/rss+xml”;
Rss20FeedFormatter formater = new Rss20FeedFormatter(fe);

XmlWriter writer = XmlWriter.Create(Response.Output, null);
formater.WriteTo(writer);
writer.Flush();
Response.End();

3 – View it in you browser or try to add it to your outlook to see the charm of creating RSS with a little effort 🙂

Reference :http://deepumi.wordpress.com/2010/03/14/create-rss-2-0-and-atom-1-0-in-asp-net-3-5-csharp/