I want some Moore

Blog about stuff and things and stuff. Mostly about SQL server and .Net
posts - 219, comments - 2287, trackbacks - 33

My Links

Advertisement

News

Hi! My name is 
Mladen Prajdić  I'm from Slovenia and I'm currently working as a .Net (C#) and SQL Server developer.

I also speak at local user group meetings and conferences like SQLBits and NT Conference
Welcome to my blog.
SQL Server MVP

My Books

SQL Server MVP Deep Dives 2
The Red Gate Guide to SQL Server Team based Development Free e-book

My Blog Feed via Email
Follow MladenPrajdic on Twitter


Users Online: who's online

Article Categories

Archives

Post Categories

Cool software

Other Blogs

Other stuff

SQL stuff

June 2006 Blog Posts

.Net Cast/Convert object to a specified type at runtime

I've been doing a "bit" of .net development lately and i had a problem where i would get a variable of type object and it's type in a string. So I wondered how to convert it to proper type at runtime. The solutions is one of those things that is unbeliveably hard to find because you don't really know what to search for, but when you find it, it seems unbeliveably simple. :) Here it is: string sType = "System.Int32"; object o1 = "123"; object o2 = Convert.ChangeType(o1, Type.GetType(sType)); Type t = o2.GetType(); // this returns Int32 Type

posted @ Friday, June 30, 2006 11:27 AM | Feedback (13) | Filed Under [ .Net ]

Sorter - a kind of ISortable implementation

I often wondered why is there no ISortable interface of somekind in .Net. I recently needed to sort items in the context menu in alphabetical order. Sorting them was the begining of a journey which produced this class. It sorts simple objects like int, string, etc... as well as complex objects that have properties you wish to sort on. EDIT: 2006-07-06 I've removed the code because I published version 2 of this class which is better and can be found here.

posted @ Tuesday, June 27, 2006 2:16 PM | Feedback (5) | Filed Under [ .Net ]

Converting System.Threading.WaitHandle.Handle to System.Threading.WaitHandle.SafeWaitHandle

I had to convert a project from .Net 1.1 to .Net 2.0 this week. It built ok with a few warnings. Amongst others there was this one: Warning: 'System.Threading.WaitHandle.Handle' is obsolete: 'Use the SafeWaitHandle property instead.' That's cool, no problem, right? As it turns out it's not just replacing one property with another. Handle property is IntPtr type and SafeWaitHandle is a class. So .Net 2.0 has a new class called SafeWaitHandle which represents a wrapper class for a wait handle. Why it's there is well explained on BCLTeam's blogs here. So what to do? It preety simple in the end. instead of _Event.Handle; just use _Event.SafeWaitHandle.DangerousGetHandle(); where _Event is...

posted @ Friday, June 23, 2006 4:50 PM | Feedback (5) | Filed Under [ .Net ]

VS 2005 and SQL Server Management Studio Keyboard Shortcuts - pure magic

If there was one thing that was going preety steadily on my nerves in VS2005 was region collapsing/opening with mouse. So i was determined to find a shortcut for it. And I found so much more... Every shortcut there is in Visual Studio 2005 is listed here. All SSMS keybard shortcuts are listed here. These two pages are the holy grail of fast development if you ask me :)) oh and by the way.... collapsing/opening a region is CTRL + M + M. Yes, hit M twice while holding CTRL. And do try CTRL + I... it's pure pleasure. a hint: Incremental Search :) <-- select text...

posted @ Friday, June 16, 2006 4:49 PM | Feedback (6) | Filed Under [ .Net SQL Server ]

The Rozenshtein Method - yet another way to pivot data in SQL Server

I've stumbled accross this post today that explains the Rozenshtein method of pivoting data. It's quite interesting. I haven't seen the SIGN() function being used at all in SQL server in practice yet so this is kind of cool if you ask me :)  

posted @ Wednesday, June 14, 2006 11:20 AM | Feedback (8) | Filed Under [ SQL Server ]

SQL Server 2005 Output Clause

I ran into this little gem today while doing some deletes and forgeting Delete syntax :))) There is now Output clause for DELETE, INSERT and UPDATE statements. It outputs the affected rows into a table variable, a simple resultset or into a table. I guess auditing is possible this way too now. Example: create table test(id int identity(1,1), name varchar(100)) insert into test (name) select 'name 1' union all select 'name 2' union all select 'name 3' union all select 'name 4' union all select 'name 5' union all select 'name 6' union all select 'name 7' union all select 'name 8' union all...

posted @ Thursday, June 08, 2006 3:58 PM | Feedback (4) | Filed Under [ SQL Server ]

Column values Concat the SQL Server 2005 way

Here's an interesting way of contencating values in one column. It makes use of the new XML capabilities. use master select column_name as col1 FROM INFORMATION_SCHEMA.Columns WHERE table_name = 'spt_values' select (select column_name as col1 FROM INFORMATION_SCHEMA.Columns WHERE table_name = 'spt_values' for xml raw, elements, type).query(' for $col1 in (row/col1) ...

posted @ Friday, June 02, 2006 11:47 PM | Feedback (1) | Filed Under [ SQL Server ]

Powered by:
Powered By Subtext Powered By ASP.NET