Rhyous http://www.rhyous.com Knight of the Code Tue, 21 May 2013 17:22:12 +0000 en-US hourly 1 http://wordpress.org/?v=3.5.1 How to execute a sql statement with a parameter in SQL Management Studio? http://www.rhyous.com/2013/05/21/how-to-execute-a-sql-statement-with-a-parameter-in-sql-management-studio/ http://www.rhyous.com/2013/05/21/how-to-execute-a-sql-statement-with-a-parameter-in-sql-management-studio/#comments Tue, 21 May 2013 11:22:12 +0000 Rhyous http://www.rhyous.com/?p=5740 Today I got asked how to execute a parameterized SQL query in SQL Management Studio.

You can do it two ways:

Method 1 – Use SP_EXECUTESQL stored procedure to execute parameterized SQL

DECLARE @query NVARCHAR(MAX) = N'SELECT * FROM customer WHERE CustomerId = @id'
DECLARE @params NVARCHAR(MAX) = N'@id int';

EXEC SP_EXECUTESQL @query, @params, @id = 3;

If you need to do multiple parameters, it is pretty much the same syntax.

DECLARE @query NVARCHAR(MAX) = N'SELECT * FROM customer WHERE CustomerId IN (@id1, @id2)'
DECLARE @params NVARCHAR(MAX) = N'@id1 int, @id2 int';

EXEC SP_EXECUTESQL @query, @params, @id1 = 3, @id2 = 4;

Method 2 – DECLARE Variables to execute parameterized SQL

DECLARE @id INT = 3;
SELECT * FROM customer WHERE CustomerId = @id;

If you need to do multiple parameters, just declare another variable.

DECLARE @id1 INT = 3;
DECLARE @id2 INT = 4;
SELECT * FROM customer WHERE CustomerId IN (@id1, @id2);
]]>
http://www.rhyous.com/2013/05/21/how-to-execute-a-sql-statement-with-a-parameter-in-sql-management-studio/feed/ 0
An HTML5 3 column layout example in ASP.NET http://www.rhyous.com/2013/05/17/an-html5-3-column-layout-example-in-asp-net/ http://www.rhyous.com/2013/05/17/an-html5-3-column-layout-example-in-asp-net/#comments Fri, 17 May 2013 07:00:32 +0000 Rhyous http://www.rhyous.com/?p=5731 A while back I posted about an html5 three column layout. Here is the same layout, only this post has built the web site using ASP.NET and it includes a Visual Studio project.

The _Layout.cshtml file looks like this:

@RenderPage("~/Layout/_Header.cshtml")
@RenderPage("~/Layout/_Nav.cshtml")
<div id="main">
   <article id="main-article">@RenderBody()</article>
    @RenderPage("~/Layout/_LeftAside.cshtml")
    @RenderPage("~/Layout/_RightAside.cshtml")
</div>
@RenderPage("~/Layout/_Footer.cshtml")

Then of course, the HTLM5 layout is in the header, asides, article, and footer. And even though the Article is placed before the asides, the asides can be either on the left or the right.

Download it here: HTLM5_ASPNET_ThreeColumnLayoutExample.zip

]]>
http://www.rhyous.com/2013/05/17/an-html5-3-column-layout-example-in-asp-net/feed/ 0
How to add a “Start” shortcut in Windows 8 (or Where is start in windows 8) http://www.rhyous.com/2013/05/16/how-to-add-a-start-shortcut-in-windows-8-or-where-is-start-in-windows-8/ http://www.rhyous.com/2013/05/16/how-to-add-a-start-shortcut-in-windows-8-or-where-is-start-in-windows-8/#comments Thu, 16 May 2013 07:00:39 +0000 Rhyous http://www.rhyous.com/?p=5726 Too many people are paying for software to provide a complete return the windows Start pop-up menu. Well, Start is still there in Windows 8, it is just a little different. It is not a pop-up menu. It is hidden by default and only shows when you move your cursor to the bottom left corner.

I think many people would be happy if they simply had a shortcut to the Apps screen, which is equivalent to All Programs.

Well, lets create a shortcut and put in on the task bar. Follow these steps.

Note: Alternately, you can download and extract the zip file from here: AllPrograms.zip

Step 1 – Create the Windows 8 Apps Shortcut

  1. Right-click on the Desktop and click New | Shortcut.
  2. Where it prompts you to “Type the location of the item” enter this:
    %windir%\explorer.exe shell:::{2559a1f8-21d7-11d4-bdaf-00c04f60b9f0}
  3. Click Next.
  4. Name the shortcut what ever you want. “Start” or “All Programs” or whatever, it really doesn’t matter.
  5. Click Finish.

Step 2 – Change the Icon for the Windows 8 Apps Shortcut

You may want to change the icon too.

  1. Right-click on your newly created shortcut and choose Properties.
  2. Click Change Icon…
  3. Select a different icon from the list or download your own .ico file and use it.

Step 3 – Drag the Windows 8 Apps Shortcut to the task bar

  1. Right-click on your newly created shortcut and choose Pin to taskbar.
  2. Now if you want this icon all the way on the left, click and drag it there.
]]>
http://www.rhyous.com/2013/05/16/how-to-add-a-start-shortcut-in-windows-8-or-where-is-start-in-windows-8/feed/ 0
Windows 8 Negativity Debunked! http://www.rhyous.com/2013/05/15/windows-8-negativity-debunked/ http://www.rhyous.com/2013/05/15/windows-8-negativity-debunked/#comments Wed, 15 May 2013 10:29:40 +0000 Rhyous http://www.rhyous.com/?p=5721 I love BSD and Linux and as an Open Source guy since 2001, many people expect me to hate Microsoft.  Well, guess what? I don’t hate Microsoft at all. I love the technology. I love most technology. So unlike many, I am not religious about my operating system. I am completely happy to spin up a Windows Server where it makes sense and a FreeBSD/Linux server where that makes sense. I am even known to run a PC-BSD desktop and avoid paying for a commercial operating system.

Currently for my desktop, I run Windows 8.

I really, truly enjoy running Windows 8. I am running it on both my laptop and my desktop. I love the Metro interface and find it works quite well for me. I use it to easily find and run my applications, just as I used Start in Windows 7. I love having both a Metro and a Desktop interface as well as having both Metro and Desktop apps.

I hear general complaints on the web.

“I miss the Start bar.”
“It’s harder to launch my apps.”
“I hate the metro interface.”

Really. Why? It is actually easier to use.

“Start is missing.” – Debunked!

Is Start really missing? No. It is there, just it has to pop up. And guess what? It even says “Start”.

Start Icon

The difference between the Start button in previous versions and the Start button in Windows 8 is not a long list.

  1. You don’t see a start button/icon until you move to the cursor all the way to the bottom left corner. However, the image that pops up does say “Start”.
  2. The screen doesn’t pop up over your current desktop view, instead it opens using the full screen.
  3. It shows both desktop apps and metro apps.

Well, are these three differences that big of a deal. Of course not. The first two are not missing features, just a different way to view things. The last one is actually a feature add.

Unfortunately, there are haters out there. Those who are religious about their operating system. Each operating system has those who are nut-job religious. Yes, I’ve seen nut-jobs for Microsoft, Apple OSX and iOS, BSD, Linux, Unix, Android. Heck, I’ve even seen nut-jobs for just one flavor of Linux (Red Hat, Debian, Ubuntu, Fedora, Slackware, Symbios, etc…). So naturally when nut jobs see a little blood in the water they attack.

Can improvements be made? Yes. I see no reason that Start has to be hidden by default. Historically, hiding or showing things has been an option. It is really the lack of the option that is all Microsoft missed. If so, that is not a big deal at all.

“It’s harder to launch my apps.” – Debunked

Windows 8 is the operating system for launching Windows applications. Historically, you have been able to launch apps in the following manner:

  1. Directly click the executable.
  2. Click a shortcut you can place anywhere (folder or desktop or Start bar)
  3. Click Start then move the cursor to All Programs, move the cursor again, and then scroll through All Apps.
  4. In Windows 7, they added the feature to click Start, just type in the first part of the program and the search would find the application for you.

Has anything changed in Windows 8. No, it hasn’t. I can still do all three with Windows 8.  What is different.

  1. Clicking Start is displayed full-screen.
  2. Getting to All Apps doesn’t require a lot of scrolling, instead it is Click Start. Right-click and choose All Apps.

These again are not feature losses but simply different views.

Go ahead and click Start, type in “No” and see that Notepad immediately shows up.

Go ahead and click Start, type in “Cont” and see that Control Panel immediately shows up.

It functions the same as Windows 7.

Is there room

“I hate the metro interface.” – Not debunked!

So let’s start with the fact that generic statements like this are just opinion and too general to really do anything about. What do you hate? Do you hate the full screen? Do you hate the way Metro Apps are opened? Lets take this to a more granular level.

“I hate seeing the full screen when I click start.” – Just opinion.

Well, this is opinion. No one can debunk or not debunk this. Personally, I don’t care either way. It works well for me, so I have no complaints.

Is there room for improvement? Yes.

I would like an option to see this in full-screen or in a window. Then those that hate it opening as full screen don’t have to have it open as full screen.

I would also like to be able to set whether to see the Start screen or the Apps screen is displayed when I click Start. However, this feature is easy to add using a shortcut. I will link to a post on how to create a shortcut to the Apps screen. You could even name the shortcut Start and put in on the bottom left.

“I hate that opening a metro app takes the whole screen”  - Not Debunked a real problem but fixable

Yes, metro apps take up the whole screen. Worse, some things, like pdf files, open in a metro app by default. I had to install Acrobat Reader to make this go away, but only for opening pdf files. Even worse is trying to figure out how to close a metro app for the first time.

This is really the only thing that bothers me about Windows 8. When I launch a metro app, it opens full screen and I have no option to make it just a window. The Metro app experience is not really that great for a desktop/laptop.

I want all my windows to be re-sizable and I want to have multiple windows up at once. So should Metro and Desktop modes be completely separated. Of course not. There is only one feature that is annoying. The fact that metro apps open full screen. Simply add an option to open metro apps in a window and now everything is fixed.

This is fixable. I may write a post on how to resolve this later. If I do, I will link to the solution here.

Conclusion

There was only one real problem, in that metro apps open full screen and you can’t run multiple apps at once. The rest are just options people want. If Microsoft makes these changes, the major complaints are resolved:

  1. Allow an option to hide or display the Start icon.
  2. Allow Start and Apps metro screens to be opened in windows.
  3. Allow Start to be configurable to either open Start or Apps metro screens.
  4. Allow a setting to make metro apps to be opened in windows and make it the default setting on desktops and laptops.

Wow! A brand new interface and really four features resolve the world’s major complaints, most of which are not really that big of complaints in the first place.

We haven’t yet discussed the new features in Windows 8 yet, such as Hyper-V, which saves me a lot of money on a separate VMWare Workstation license.

My Recommendation

Take another look at Windows 8!

]]>
http://www.rhyous.com/2013/05/15/windows-8-negativity-debunked/feed/ 0
Android Virtual Device (AVD) extremely slow http://www.rhyous.com/2013/04/29/android-virtual-device-avd-extremely-slow/ http://www.rhyous.com/2013/04/29/android-virtual-device-avd-extremely-slow/#comments Mon, 29 Apr 2013 15:50:35 +0000 Rhyous http://www.rhyous.com/?p=5716 So I started to look at writing an Android app. I took a class on Android and wrote a prototype Android App in fall of 2011. Well, I have a need to write an Android App again.

I am a C# developer and while I am comfortable with Java, I prefer C# so I am going to use MonoDroid.

I installed everything very easily using the MonoDroid installer. However, when I went to launch an Android Virtual Device (AVD) it seemed to start but even after leaving it over night, it didn’t finish booting.

So I did some research and the recommendation was to install the Hardware Accelerated Execution Manager.

So I had to:
1. Open the Android SDK Manager and install the Intel x86 Emulator Accelorator (HAXM).

2. Run the installer I found here:
C:\Users\jbarneck\AppData\Local\Android\android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager\IntelHaxm.exe

After that, opening an AVD was plenty fast.

]]>
http://www.rhyous.com/2013/04/29/android-virtual-device-avd-extremely-slow/feed/ 0
Using knockout.js and MVVM with RadioButtons http://www.rhyous.com/2013/04/11/using-knockout-js-and-mvvm-with-radiobuttons/ http://www.rhyous.com/2013/04/11/using-knockout-js-and-mvvm-with-radiobuttons/#comments Thu, 11 Apr 2013 06:31:24 +0000 Rhyous http://www.rhyous.com/?p=5697 In the example below, radio buttons selection list is created by binding to a list in the view model. I show how to bind to both the selected radio button’s value and name. I also show how to disable a button unless the radio button is selected.

<!-- Step 1 - Create the HTML File or the View -->
<!DOCTYPE html>
<html>
<head>
    <!-- Step 2 - Include jquery and knockout -->
    <script type="text/javascript" src="scripts/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="scripts/knockout-2.2.1.js"></script>
    
    <!-- Step 3 - Add script to run when page loads -->
    <script type="text/javascript" >
        $(document).ready(function(){

			<!-- Step 4 - Add a RadioButtonModel -->
            function RadioButtonModel(inText, inValue, inGroupName) {
                this.text = inText;
				this.value = inValue;
				this.name = inGroupName;
            }

			<!-- Step 5 - Create ViewModel -->
            function SurveyViewModel() {
                var self = this;
                
				<!-- Step 7 - Create an observable list -->
                this.list = ko.observableArray([
                    new RadioButtonModel("Good", 10, "Q1"),
                    new RadioButtonModel("Average", 5, "Q1"),
                    new RadioButtonModel("Poor", 1, "Q1")
                ]);
				
				<!-- Step 8 - Create a selected item -->
				this.selected = ko.observable(0);
				
				<!-- Step 9 - (Optional) Create a computed value to get the selected text -->
				this.selectedtext = ko.computed(function() {
					var text = "";
				    ko.utils.arrayForEach(this.list(), function(item) {
						var selectedItem = self.selected();
						if (selectedItem == item.value)
							text = item.text;
					});
					return text;
				}, this);
				
				
				<!-- Step 10 - Create a computed value to require a selection before submitting -->
			    this.canClick = ko.computed( function() {
                    return this.selectedtext() != "";
                }, this);
                
            }
            
            <!-- Step 10 - Create a computed value to require a selection before submitting -->    
            ko.applyBindings(new SurveyViewModel());
        });
    </script>
</head>
<body>
    <!-- Step 11 - Create a div containing the html for one radio button and bind to foreach: list -->
    <div data-bind="foreach: list">
        <input type="radio" data-bind="attr: {name: name}, value: value, checked: $root.selected" /><span data-bind="text: text"></span>
    </div>

    <!-- Step 12 - Add html elements to see other properties -->
    <p data-bind="text: selected"></p>
    <p data-bind="text: selectedtext"></p>
    
    <!-- Step 13 - Add a button and bind its enable state -->
    <button type="submit" id="btnSubmit" data-bind="enable: canClick">Submit</button>

</body>
</html>

Hope this helps you.

]]>
http://www.rhyous.com/2013/04/11/using-knockout-js-and-mvvm-with-radiobuttons/feed/ 0
Using MVVM with HTML5 and JavaScript http://www.rhyous.com/2013/04/09/using-mvvm-with-html5-and-javascript/ http://www.rhyous.com/2013/04/09/using-mvvm-with-html5-and-javascript/#comments Tue, 09 Apr 2013 21:17:57 +0000 Rhyous http://www.rhyous.com/?p=5691 The MVVM pattern is an excellent pattern for separating the UI or View and the Code or ViewModel and Model.

With Knockout.js the MVVM pattern can be used with HTML5.

Previously I wrote this post: Using jQuery to enable/disable a button based a text box

This same thing could be done using binding and the MVVM pattern, with jQuery and Knockout.js.

Here is a single file example of using knockout.js and with databinding.

<!-- Step 1a - Create the HTML File or the View -->
<!DOCTYPE html>
<html>
<head>
    <!-- Step 2 - Include jquery and knockout -->
    <script type="text/javascript" src="scripts/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="scripts/knockout-2.2.1.js"></script>
    
    <!-- Step 3 - Add script to run when page loads -->
    <script type="text/javascript" >
        $(document).ready(function(){
        
            <!-- Step 4 - Create a ViewModel -->
            function BasicViewModel() {
            
                <!-- Note: In this case the model is just a string and a bool -->
                <!-- Step 5 - Create a text property to bind the text to -->
                this.text = ko.observable('');
                
                <!-- Step 6 - Create a bool property to bind the button enabled state to -->
                this.canClick = ko.computed(function() {
                    return this.text() != null && this.text() != '';  
                    }, this);
                }
          
            <!-- Step 7 -  Activates knockout.js bindings -->
          ko.applyBindings(new BasicViewModel());
        });
    </script>
</head>
<body>

    <!-- Step 8 - Create a HTML Elements with bindings -->
    <input data-bind="value: text, valueUpdate:'afterkeydown'" />
    <button type="button" id="btnEnter" data-bind="enable: canClick">Enter</button>
</body>
</html>

Anyone who knows MVVM will surely realize that while this example is all in a single file, it is likely that you will have a separate viewmodel javascript file in a production environment.

]]>
http://www.rhyous.com/2013/04/09/using-mvvm-with-html5-and-javascript/feed/ 2
Support Tools for LDMS 9.5 Released http://www.rhyous.com/2013/03/29/support-tools-for-ldms-9-5-released/ http://www.rhyous.com/2013/03/29/support-tools-for-ldms-9-5-released/#comments Fri, 29 Mar 2013 04:24:33 +0000 Rhyous http://www.rhyous.com/?p=5685 Support Tools for LDMS 9.5 Released

Go here for more information:

http://www.rhyous.com/programming-development/landesk-add-ons/landesk-support-tools/

]]>
http://www.rhyous.com/2013/03/29/support-tools-for-ldms-9-5-released/feed/ 0
SQL INSERT statement syntax is poorly designed http://www.rhyous.com/2013/03/20/sql-insert-statement-syntax-is-poorly-designed/ http://www.rhyous.com/2013/03/20/sql-insert-statement-syntax-is-poorly-designed/#comments Wed, 20 Mar 2013 11:52:33 +0000 Rhyous http://www.rhyous.com/?p=5675 Am I on the only in the technical community that is completely annoyed by SQL’s INSERT statement syntax? Especially with long INSERT queries.

Why in the world do we have to have the column and its value separated.

Imagine this table, which is an overly simplified example only version of a Person table.

FirstName MiddleName LastName Birthday UserName Password PhoneNumber Address SignupDate LastUpdated LastPasswordChange

Please not that this table only has 10 columns. I am working with tables with three of four times as many columns. Also these columns are pretty simple. Many columns have name like PK_D or other cryptic titles.

So wouldn’t it be nice to have a syntax that more easily connects the column and the value?

Lets look at the insert syntax:

INSERT INTO Person (FirstName, MiddleName, LastName, Birthday, UserName, Password, PhoneNumber, Address, SignupDate, LastUpdated, LastPasswordChange)
VALUES ('John', 'J.', 'Doe', '3/27/1977', 'jdoe', 'p@ssw0rd!, '555-555-5555, '1234 ABCD Street SomeCity, Utah 81234', '12/1/2012', '3/20/2013', '3/13/2013')

Ok, so you can start to see how even with these easy and well-known columns, it starts to get confusing as to which order you need to enter data. Also, you have to scroll right to left a lot. Also, in whichever order you type your column names, you have to enter you data.

Even with every value on its own line, this is still not very clear.

INSERT INTO Person (
FirstName, 
MiddleName, 
LastName, 
Birthday, 
UserName, 
Password, 
PhoneNumber, 
Address, 
SignupDate, 
LastUpdated, 
LastPasswordChange)
VALUES (
'John', 
'J.', 
'Doe', 
'3/27/1977', 
'jdoe', 
'p@ssw0rd!, 
'555-555-5555, 
'1234 ABCD Street SomeCity, Utah 81234', 
'12/1/2012', 
'3/20/2013', 
'3/13/2013')

Now it is a lot of lines, and you have just swapped extensive left and right scrolling to up and down scrolling. Remember, this is a small table. Some tables have many times more columns.

Of course you can get around some of this using default values and allowing NULLs so you don’t have to insert values for those columns. But if you have 30+ required columns, which the database I am working with has, then that doesn’t help. No, I am not in control of the database or I would likely change it.

Why is the syntax not something that is order insignificant?

INSERT INTO Person
FirstName='John', MiddleName='J.', LastName='Doe', Birthday='3/27/1977'
UserName='jdoe', Password='p@ssw0rd!, PhoneNumber='555-555-5555,
Address='1234 ABCD Street SomeCity, Utah 81234', SignupDate='12/1/2012',
LastUpdate='3/20/2013', LastPasswordChange='3/13/2013'

Or all on its own line:

INSERT INTO Person
FirstName='John', 
MiddleName='J.', 
LastName='Doe', 
Birthday='3/27/1977'
UserName='jdoe', 
Password='p@ssw0rd!, 
PhoneNumber='555-555-5555,
Address='1234 ABCD Street SomeCity, Utah 81234', 
SignupDate='12/1/2012',
LastUpdate='3/20/2013', 
LastPasswordChange='3/13/2013'

Is it just me who thinks that the standard property=value syntax is a quite a bit more readable and a lot more writable?

I am sure there are all kinds of reasons why this syntax isn’t used. I am not saying property=value syntax is a fix to the horrible INSERT syntax. I am just saying that the INSERT syntax is horrible and I would recommend that future version of SQL provide and more readable a more writable alternative.

]]>
http://www.rhyous.com/2013/03/20/sql-insert-statement-syntax-is-poorly-designed/feed/ 4
How to export table data into a SQL insert script? http://www.rhyous.com/2013/03/09/how-to-export-table-data-into-a-sql-insert-script/ http://www.rhyous.com/2013/03/09/how-to-export-table-data-into-a-sql-insert-script/#comments Sat, 09 Mar 2013 06:30:00 +0000 Rhyous http://www.rhyous.com/?p=5627 Have you ever had a table that you wanted to drop and recreate but you need all the data inside it. Perhaps it took you a lot of time to generate this data.

Well, you can save the data out as a SQL insert script if you want. Here is how:

  1. Open Microsoft SQL Server Management Studio and login.
  2. Right-click on the database and choose Tasks | Generate Scripts.
    Note: The first time you do this you will see and Introduction page. Click Next. You can click the check box next to Do not show this page again and you won’t see this screen.
  3. On the Choose Objects screen, click Select specific database objects.
  4. Expand Tables and click the check box next to the table you want to save and click Next.
  5. On the Set Scripting Options screen, click Advanced.
  6. Scroll down and under Types of data to script select Data only and click OK.
  7. Under File name select a file name to save to and click Next.
  8. Click Next, Next, Finish.

You now have a script to insert your data.

]]>
http://www.rhyous.com/2013/03/09/how-to-export-table-data-into-a-sql-insert-script/feed/ 2