Visual studio feeds

All Visual Studio blogs in one place


Enter your email address:

Delivered by FeedBurner

Increase your website traffic with



Anti-spam: How many eyes has a typical person?

Follow us on FB


Removing columns with all NULL values

AddThis Social Bookmark Button
Recently in this thread I solved an interesting problem - how to inspect table for the presence of columns that don't have data (all values in these columns are NULL) and remove them from the table.
I used my favorite idea of constructing a dynamic query using INFORMATION_SCHEMA.COLUMNS view. 

Let's first create our sample table and call it Items:
USE tempdb SET NOCOUNT ON; CREATE TABLE Items (Barcode VARCHAR(100) NULL, ItemID INT NOT NULL, ItemName VARCHAR(100)) INSERT INTO Items (ItemID, ItemName) VALUES (1, 'Apple') And now this is how I solve the problem: DECLARE @SQL NVARCHAR(MAX), @OutputCommand nvarchar(max) SET @OutputCommand = '' SET @SQL = STUFF((SELECT CHAR(13)
+ CASE WHEN IS_NULLABLE = 'NO' THEN NULL ELSE 'IF NOT EXISTS(SELECT 1 FROM dbo.Items WHERE ' + QUOTENAME(Column_Name) + ' IS NOT NULL) SET @OutputCommand = @OutputCommand + CHAR(13) + ''ALTER TABLE dbo.Items DROP COLUMN ' + QUOTENAME(Column_Name) + '''' END FROM INFORMATION_SCHEMA.COLUMNS WHERE Table_Name = 'Items' AND TABLE_SCHEMA = 'dbo' ORDER BY Ordinal_Position FOR XML PATH(''),Type ).value('.','nvarchar(max)') ,1,1,'') SET NOCOUNT ON; EXECUTE SP_EXECUTESQL @SQL, N'@OutputCommand nvarchar(max) OUTPUT', @OutputCommand OUTPUT PRINT @OutputCommand --EXECUTE (@OutputCommand) -- to actually drop columns I generate the ALTER TABLE DROP COLUMN command dynamically and output...(Read whole news on source site)

Sum up digits of a number

AddThis Social Bookmark Button
My friend told me that in an interview he was asked to write a code that sums the digits of the number. He asked me if there is a way of doing it without using a WHILE loop. Here are two methods Method 1 : Dynamic SQLdeclare @i int, @sql varchar(8000) set @i=798273 set @sql='' select @sql=@sql+substring(ltrim(@i),number,1)+'+' from master..spt_values where type='p' and number between 1 and len(@i) select @sql='select '+left(@sql,len(@sql)-1) exec(@sql+' as sum_of_digits') Method 2 : Static SQLdeclare @i int, @n int set @i=798273 set @n=0 select @n=@n+substring(ltrim(@i),number,1) from master..spt_values where type='p' and number between 1 and len(@i) select @n as sum_of_digits Method 3 : Without using any variablesdeclare @i int set @i=798273 select
sum(substring(ltrim(@i),number,1)*1) from master..spt_values where type='p' and number between 1 and len(@i) All the methods would return the following resultsum_of_digits ------------- 36 Here master..spt_values is a system table which is used as a tally number table. You can use your own table too....(Read whole news on source site)

Temporary table and dynamic sql

AddThis Social Bookmark Button
One of my collegues told me that while we cannot use a temporary table created inside dynamic sql out of it, in a similar way it is not possible inside dynamic sql to access a temporary table created out of dynamic sql. How many of you think this is true? I immediately showed him the following code to prove him wrong.create table #t (i int) GO exec ('insert into #t(i) select 100') GO select i from #t The result is 100. As you see it is possible to access the temporary table via dynamic sql in the current session. Ok now the question is "How do
I know what objects I can access via dynamic sql?". You can access all the objects that you see from sys.objects. You need to aware of this when using temporary table and dynamic sql.

You may also be interested to read this post Scope of temporary tables across procedures...(Read whole news on source site)

Positive Quotes for Work and Life

AddThis Social Bookmark Button
When life throws you a nasty curve ball, or when the best laid plans of mice and men go awry, it can be tough to look on the bright side.   But that’s what leaders do.  Whether you are a leader or developing your own self-leadership, positive quotes can serve you well.   They fortify the mind.   And where there’s a will, there is often a way. Positive thinking helps breed positive action.   A positive mindset can help you see opportunities you might otherwise miss.   A positive mindset can also help you break out of limiting loop and self-defeating patterns.   They
can lift yourself and those around you.  Positivity is contagious and it’s worth spreading. I’m not a positive thinker of the Pollyanna kind, but I’ve learned through habit and practice to look for the sliver lining in the cloud, before dwelling on the rain.  I’ve also learned that crying over spilled milk just leaves a slippery floor, and that the fastest way to change the situation, is to change yourself.   The most important lesson I’ve learned is that opportunity comes to those who seek it. Don’t let possibilities pass you by.   If you need a new lease on...(Read whole news on source site)

Das war die dotnet Cologne 2012

AddThis Social Bookmark Button
Am 4. Mai fand zum vierten Mal die dotnet Cologne Konferenz statt und war – wie bereits in den Vorjahren – ein großer Erfolg. Organisiert von den .NET User Groups Bonn-to-Code.Net und .net user group Köln unter der Schirmherrschaft des dotnet Köln/Bonn e.V., ist diese .NET Community Konferenz mit 350 Teilnehmern mittlerweile deutschlandweit die größte ihrer Art. Als Veranstaltungsort diente wieder das Komed im Mediapark Köln, das Platz, Ambiente, Verkehrsanbindung und nicht zuletzt Finanzierbarkeit hervorragend miteinander vereint. Das Komed-Personal war wieder sehr hilfsbereit und
professionell, die Technik (Audio, Video, WLAN) funktionierte – was will man als Veranstalter (Stefan Lange, Melanie Eibl, Albert Weinert und ich) mehr? Für mich persönlich war die dotnet Cologne auch deshalb eine interessante Erfahrung, weil ich in ungewohnter Rolle als Interviewer für das offizielle Veranstaltungsvideo unterwegs war. Vor meinem Mikro tummelten sich Teilnehmer… …Sponsoren… …und Sprecher: Der Ergebnis ist demnächst auf der dotnet Cologne Website zu bewundern. Was man gar nicht meinen möchte: Wie sehr...(Read whole news on source site)

Why I will always love RSS

AddThis Social Bookmark Button
There has been a lot of noise in the tech community earlier this year about how RSS is supposedly having one foot in the grave. If that would be even remotely true, I hope it dies with its boots on. The herald would be browsers and social networking sites killing or hiding support for RSS. While that may be true, their motives shouldn't rig our opinions.

RSS has never worked out for the regular consumer, not directly anyways. So I get why browsers are dropping support for it, I am not even disappointed. Most popular social networks have enough traction by
now so that they can safely start fencing their gardens with the purpose of bringing more money in. Also reasonable.

What startles me is when peers start advertising the death of RSS. The explanations I hear are somewhere along the lines of "Why use RSS? I count on the people I follow on Twitter to share links to good information", or similarly "I just check Hacker News a few times a day to read up on the latest news". I strongly believe the contemporary fetish of liking and sharing cheapens the way we consume our information. Don't get me...(Read whole news on source site)

Install-NuSpec & Enable-PackagePush: create, build & push NuGet packages anywhere

AddThis Social Bookmark Button
This short post is basically combining some of my recent posts (this one and that one) into one. Actually, into one single NuGet package :)  Basically, this one single package will allow me to automate and speed up package creation and publication, and it will run anywhere you can run the NuGet command line, because I only use nuget.exe and MSBuild to perform these actions. To set it up, I use a NuGet package (Install-Package NuSpec) and some PowerShell, but that's only to put the pieces of the puzzle in the right place, and give you some commands
in Visual Studio. Once you're done, simply uninstall the package. So, in short: Enable Package Restore to get the .nuget folder (which contains nuget.exe and some nuget.targets file I'll extend) Install-Package NuSpec (once per solution, target project doesn't matter) Install-NuSpec [-EnablePackageRestore] (for every project you want to trigger a package build) Enable-PackagePush (for every project you want to enable auto-push) Uninstall-Package NuSpec (once you're finished with steps 1-4 for the solution)
A more detailed Readme is available on Github (where the sources are if you fancy some PowerShell).
The package can be found on NuGet.
If you're using MyGet...(Read whole news on source site)

Extending ASP.NET MVC Account Registration with Workflow (WF4)

AddThis Social Bookmark Button
One thing that many web sites do is to verify email addresses by sending you an email to complete registration.  I decided to build a Registration system for ASP.NET MVC using Windows Workflow Foundation. When you create a new ASP.NET MVC web site, the site comes with a simple account controller that integrates with ASP.NET Membership.  It provides basic one step registration and log-in support.  I wanted to take this much farther and provide a simple self-contained registration verification system. Scenarios When I plan work like this, my first step is to prepare the list of scenarios
I'm working on so I don't get distracted and don't miss anything important Given When Then A user registers for the site with a valid email address ...(Read whole news on source site)

JSON deserialization with caching results

AddThis Social Bookmark Button
On January 22 I promised this to be a three-part series. I’ve been kinda busy with upgrading apps, Windows 8 experiments and trivial ;-) stuff like code camps, an MVP summit, preparing my first and second talk about Windows Phone and whatnot and made you wait for the final part for exactly three months – but those who know me, know I stick my promises, so here’s the third and final part of my JSON for Windows Phone series. In part 1 of this series I described the basics of creating classes
from a JSON string and then simply deserializing the string into a (list of) classes. In part 2 I showed how to use JSONConverter subclasses to handle complex stuff the deserializer cannot handle out of the box, like class hierarchies. Part 3, as promised, shows a way to cache results - which makes your application faster, more responsive and more battery/data plan friendly. Using the demo solution of part 2 as a starting point, I first brought in my wp7nl library on codeplex using NuGet. I am lazy just like any programmer (should be)...(Read whole news on source site)