Wednesday, May 23, 2012

Forcing an Identity ID into a SQL Table

If you're ever in a situation where you messed up and deleted a record, and you need to insert back in a record.. and the primary key has to be what you WANT it to be, and not what the auto-increment adds for you, here's how you do it:

 SET IDENTITY_INSERT ON
INSERT INTO ... 


 Very simple but handy little tool to know.

Monday, April 23, 2012

Word Wrap Css

Today I discovered a new css trick thanks to one of my coworkers at gvpi. I had a grid that would break whenever the string was way to long, for example, if the string said something like, "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", it would break the styles on the page because the content wouldn't fit nicely into the column I created.

Apparently now there's a trick with the newer browsers called word-wrap. Here's a link:
http://webdesignerwall.com/tutorials/word-wrap-force-text-to-wrap

Basically, it's just a css tag that looks like this: word-wrap:break-word;

Voila! That's it!

Friday, March 30, 2012

Broken Image?

Recently I found a really cool way to handle "broken images". This happens all the time when you have a some sort of auto-generated image, or an expected image but then sometimes the file doesn't exist, or something happened to it. Here is one fairly cheap way to set up a default image:

http://stackoverflow.com/questions/717734/best-way-to-display-default-image-if-specified-image-file-is-not-found


In other words, something like this:
<img src="image.jpg" onerror="this.onerror=null;this.src='default.jpg'">

So far I've tested in ie9, chrome, and firefox and works in all three. Pretty cool!

Tuesday, February 14, 2012

Div over a Youtube Video?

If you've ever had trouble with a lightbox or any other floating div being overshadowed by an embedded youtube video on your site, here's a very easy way to fix:

How to Fix the Embedded YouTube iFrame z-index Problem
Here’s the parameter you should add to the YouTube URL in the iFrame embed code:

?wmode=transparent

Example iFrame code:
<iframe title=”YouTube video player” width=”525″ height=”325″ src=”http://www.youtube.com/embed/ucowE8dtNqM” frameborder=”0″ allowfullscreen> </iframe>

Code With Fix Applied:
<iframe title=”YouTube video player” width=”525″ height=”325″ src=”http://www.youtube.com/embed/ucowE8dtNqM?wmode=transparent” frameborder=”0″ allowfullscreen></iframe>

I got the answer from:
http://www.jenkaufman.com/youtube-iframe-embed-video-problem-hides-menus-other-layers-546/

Hopefully this will save someone from having to rip through their CSS to find a solution!

Friday, February 10, 2012

A Cool .NET Class for formatting Time

Here's a quick little class I discovered in the framework that helps you format time.

It's called the timespan class, and here's an example:

VB
Dim t As New TimeSpan(0, 538, 0)

'Then you have the 2 properties
t.Hours
t.Minutes

C#
var t = new TimeSpan(0, 538, 0);

//Then you have the 2 properties
t.Hours
t.Minutes

Pretty cool little class! For more info click here:
http://msdn.microsoft.com/en-us/library/system.timespan.aspx

Wednesday, February 1, 2012

How to Kick People off SQL Server

Sometimes when you try to do something in SQL, like a db restore, it won't let you because of an active connection. If you want to see who it is that's locking up your DB and you want to kick them off, take the following steps:

sp_who - This returns a set of data with all activity on the database. Each connection will have a spid.

kill <spid> - This kills the spid.

Happy killing!

Tuesday, January 31, 2012

Bitwise Logic in C#, and HasFlag

Hey, if you're ever using bitwise logic, or you want to know how to use bitwise logic, check out this post:

Bitwise Logic

One of the cool new features is the HasFlag() method in .NET 4.0 that lets you quickly verify if a bit has been flagged or not. The HasFlag is at the bottom of the page. I wish I could write more about this, but NO TIME!! Maybe I'll expand on it later. Ciao!

Line Numbers in Visual Studio

Here's a simple little feature that I never realized I could do. Did you know that you can actually view LINE NUMBERS in Visual Studio? YES! I'm sure all 1 of you who are reading this are like, "DUH!!", but I didn't know how to do it. If you want to see how, read this here:

How to Display Line Numbers in Editor

Oh, and you're welcome, DUH!!

Wednesday, January 18, 2012

Change Browser Plug-in

I posted something a while ago about how to change browsers in Visual Studio, but it can be problematic when using the MVC framework, because VS won't let you browse templates or Views directly in a browser like you can with Web Forms - which lead me on a short search down the interwebs where I found this solution!

For Visual Studio 2010, there's a downloadable plug-in available that will let you change your browser on the fly. Check out:

http://visualstudiogallery.msdn.microsoft.com/bb424812-f742-41ef-974a-cdac607df921

I'm using it now and it's awesome. It puts a little toolbar at the top of the IDE with icons for all the browsers you have installed on your PC so you can switch between them. Browsers available are ie, firefox, chrome, safari, and opera. This makes switching browsers even EASIER, and I've found it to be pretty nifty.

Oh, and according to Microsoft, a similar toolbar will come built in with Visual Studio 2011. Purty cool!

Saturday, January 14, 2012

Creating Custom Exception Types in .NET

There's going to come a time when you need to create a custom Exception type. Of course, there are always people who will go overboard and use a custom exception type instead of actually coding a check to prevent the exception, which is very bad, but that's now what this post is about. What it IS about is how to do it.. so I'll post a link to some guy who wrote it all out for me already.

http://blog.gurock.com/articles/creating-custom-exceptions-in-dotnet/

Me = SOooooo lazy.