Posts

Showing posts from March, 2013

Donate

Optimizing SQL TOP Queries In MSSQL Database

Here's an interesting article on optimizing queries using Top statement to filter result sets: Why SQL Top may slow down your query? The solutions are the following: 1. using Hash joins SELECT TOP 5 [Articles].Id ,CountryCategories.Name ,CityCategories.Name FROM [Articles] INNER HASH JOIN CategoryCountry2Articles ON [Articles].Id = CategoryCountry2Articles.IdArticle INNER HASH JOIN CountryCategories ON CountryCategories.Id = CategoryCountry2Articles.IdCountry INNER HASH JOIN CategoryCity2Articles ON [Articles].Id = CategoryCity2Articles.IdArticle INNER HASH JOIN CityCategories ON CityCategories.Id = CategoryCity2Articles.IdCity WHERE CountryCategories.Name = 'country1' AND CityCategories.Name = 'city4' 2. Using Variables. DECLARE @topCount INT SET @topCount = 5 SELECT TOP (@topCount) (...) I am pretty much interested why using variables is much faster. Compared with other findings

IOrderedQueryable<T> Extension Method (C#)

Here's a modified version of Nick Harrison's IOrderedQueryable extension method in his dynamic linq query post: static class IQueryableExtensions { public static IOrderedQueryable<TSource> GenericEvaluateOrderBy<TSource>( this IQueryable<TSource> query, string propertyName) { var type = typeof (TSource); var property = type.GetProperty(propertyName); var parameter = Expression.Parameter(type, "p" ); var propertyReference = Expression.Property(parameter, property); //p.ProductName var sortExpression = Expression.Call( typeof (Queryable), "OrderBy" , new Type[] { type, property.PropertyType }, query.Expression, Expression.Quote(Expression.Lambda(Expression.MakeMemberAccess(parameter, property), parameter))); return query.Provider.CreateQuery<TSource>(sortExpression) as IOrderedQueryable<TSource&g

Regular Expression Remove Day Name And Date Suffix In C#

In a situation where i want to format this date value from (Tuesday 19th March 2013) to (19 March 2013). I made a regular expression by applying look behind approach and ends with behavior in strings. Here's the expression: indicatorDate = Regex.Replace(indicatorDate, @"(\b[A-Za-z]*day\b)|((?<=[0-9])[a-zA-z]{2})" , string .Empty, RegexOptions.IgnoreCase); :)

How To List Tables In A MSSQL Database With Criteria

Here are some simple T-SQL statements to show table information with set of criterias. -- show tables sort by name ascending use DatabaseName go select * from sys.tables order by sys.tables.name asc go -- show tables that starts with s use DatabaseName go select * from sys.tables where upper (sys.tables.name) like 'S%' ; go -- show tables sort by date created descending use DatabaseName go select * from sys.tables order by create_date desc ; go -- show tables where type description is user use DatabaseName go select * from sys.tables where type_desc like lower ( '%user%' ) go Reference: BOL

ASP.NET MVC Implementing MVCContribGrid CustomPagination<T> Class

Image
Out of boredom, I came upon a class named CustomPagination in MVCContrib that that implements IPagination , IEnumerable and other interfaces that you can customize your paging needs.Here's the class definition: namespace MvcContrib.Pagination { public class CustomPagination <T> : IPagination<T>, IPagination, IEnumerable<T>, IEnumerable { public CustomPagination(IEnumerable<T> dataSource, int pageNumber, int pageSize, int totalItems); public int FirstItem { get ; } public bool HasNextPage { get ; } public bool HasPreviousPage { get ; } public int LastItem { get ; } public int PageNumber { get ; } public int PageSize { get ; } public int TotalItems { get ; } public int TotalPages { get ; } public IEnumerator<T> GetEnumerator(); } } I found an article in this blog( http://lsd.luminis.eu ) on how to use the CustomPagination class that r

Change Cell Url Contents To Hyperlinks Using VBA In MS Excel

Hello! Assuming in your MS Excel Worksheet you have thousands of cells that contains url and you want them to be a hyperlink. It can be done manually, but tedious. Another solution is to write a VBA (Visual Basic for Applications) Script to do that for you using the Sub procedure below that will convert an Excel cell content to hyperlink. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Sub ChangeCellsToHyperlinks() Dim rng As Range Dim ctr As Integer Dim range_name As String ctr = 2 'starting cell to change Do While ctr <= 10000 'end cell range Set rng = ActiveSheet.Range( "A" & ctr) rng.Parent.Hyperlinks.Add Anchor:=rng, Address:=rng With rng.Font .ColorIndex = 25 .Underline = xlUnderlineStyleSingle End With ctr = ctr + 1 Loop End Sub That's it!

Show Label Count of Category Label (Blogger)

When I applied a new template to blogger, the category label count disappears. So, I searched google and found this site on blogger tricks that shows how to customize labels. http://dummies.bloggertipsandtricks.com/ So, I applied it in the expression expr:href='data:label.url'. <a expr:href= 'data:label.url' ><data:label.name/></a> Then, I applied the trick to show the label count. <a expr:href= 'data:label.url' ><data:label.name/></a> <span dir= 'ltr' >(<data:label.count/>)</span> Cheers!

Keyword not supported: “data source” (Passing Connection String Of Type EF to EF constructor)

Assuming you have a connection string that points to an Entity Framework object. And in your connection class, you pass the connection string to the Entity Framework constructor below: customerEntity = new Database1Entities(_connectionString); You encountered an error Keyword not supported: "data source". The solution is presented here: Keyword not supported data source initializing entity framework context It suggests to replace the &quot word with single quote (') character. So, in this case, I used Regex to perform replace operation. return Regex.Replace(ConfigurationManager.ConnectionStrings[key].ToString(), @"&quot" , "'" , RegexOptions.IgnoreCase);

Donate