Linq to SQL (1)


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in D:\InetPub\vhosts\kwu-1639.package\kennywu.info\wwwroot\wp-content\plugins\wp-syntax\wp-syntax.php on line 380

You can crate a Plain Old CLR Object to map the underlining database table w/o the help of the LINQ-to-SQL designer. To represent a customer class, you need the following code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Text;
 
namespace LinqToSql
{
    [Table(Name="Customers")]
    public class Customer
    {
        [Column]
        public string customerId {get; set;}
        [Column]
        public string companyName {get; set;}
        [Column]
        public string city {get; set;}
        [Column]
        public string country {get; set;}
    }
 
    class LinqToSql
    {
        static void Main(string[] args)
        {
            string connString = @"Server=.SQLEXPRESS; 
            Database=Northwind; Trusted_Connection=Yes";
            DataContext db = new DataContext(connString);
 
            // crate typed table
            Table<Customer> customers = db.GetTable<Customer>();            
            //query database
            var custs = from c in customers
                        where c.country =="USA"
                        select c;
            //display customers
            foreach (var cust in custs)
            {
                Console.WriteLine(
                    "{0} {1} {2} {3}", 
                    cust.customerId, cust.companyName, cust.city, cust.country
                    );
            }
            db = null;
        }
    }
}

Implement RSS news feed in .Net


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in D:\InetPub\vhosts\kwu-1639.package\kennywu.info\wwwroot\wp-content\plugins\wp-syntax\wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in D:\InetPub\vhosts\kwu-1639.package\kennywu.info\wwwroot\wp-content\plugins\wp-syntax\wp-syntax.php on line 380

There are many ready to use RSS wrappers on the net, the one from Web Service Share is easy to use and comes on top from Google search.
Download two DLL,

  • Wss.Common.dll
  • Wss.News.WebService.PcWorldNews.GetDataFeed.dll

from Class Library add them to the Bin folder. Add the following snippet to the aspx markup.

<asp:Literal ID="Literal1" runat="server" EnableViewState="False"></asp:Literal>

The code behind file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using Wss.Common;
using WebServices = Wss.News.WebServices;
using Rss = Wss.News.Rss20;
 
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int _rssNum = 10;
        Rss.Result rssResult = WebServices.PcWorldNews.GetDataFeed();        
        foreach (var _rss in GetRss.SelectRss(rssResult,   _rssNum))
        {
            Literal1.Text += String.Format("<a href="{1}">{0}</a><br /><hr />", 
                _rss.Title, _rss.Link);
        }        
    }
}
 
public struct aRss {
    public string Title { get; set; }
    public string Link { get; set; }    
    //public string Description { get; set; }    
}
static public class GetRss {    
 
    static public List<aRss> SelectRss(Rss.Result rssResult, int _rssNum)
    {        
        List<aRss> allRss = new List<aRss>();
        for (int i = 0; i < Math.Min(_rssNum, rssResult.Items.Count); i++)
        {
            allRss.Add(new aRss
            {
                Title = rssResult.Items[i].GetTitle(""),
                Link = rssResult.Items[i].GetLink(""),
                //Description = _item.GetDescription("")                
            }
            );
        }        
        return allRss;
    }
}

The class will return only the first 10 entries. The number is specified by the variable “_rssNum”.

Add a lookup entry in local DNS

After you enter a web address, Windows OS will search a local DNS to find out corresponding IP address. If it could not find it there, it will go to DNS server to search for it. Old days people used to add those often visited addresses to a local DNS file to seep up the Internet surfing experience. Currently with hi peed Internet connection, the practice will not yield any noticeable difference. However, if you have a intranet and you want to go to internal address by calling its external address, that is the way to go.
To edit your local DNS lookup file, go to
C:WindowsSystem32Driversetc
Using a text editor like notepad to open the file hosts
Add an entry at the bottom with two information: the IP address and the customized domain name, separated by a single space.
192.168.1.5 wukenny.homeserver.com
192.168.1.5 www.wukenny.homeserver.com

This works in both windows xp and windows 7. In Win7 you might need to copy the file to another location get it edited and then pasted it back due to the stringent user control.