Subscribe to Alvin Poh's Blog by RSS reader
Subscribe to Alvin Poh's Blog by Email
Gadgets, Technology, Public speaking and IT from an undergraduate's perspective.
How To Create a Stored Procedure using C#, SQL Server 2008, Visual Studio 2008
Microsoft’s Visual Studio 2008 is amazing. It truly is an integrated development environment, because EVERYTHING is integrated. I just learnt about stored procedures today and how creating stored procedures is so easy in Visual Studio. Here’s the steps that you need.
- In Visual Studio, create a solution if you haven’t, and to that solution, add a project of the type “SQL Server Project”
- Next, right click on that project (not the solution) and add an item of the type “Stored Procedure”, and choose “Stored Procedure” as the sub-type that we want.
- You should see the stored procedure added to your project as a file. I’m using C#, so it’s added as a new C# file, with some template code added already.
- Try adding this code chunk:
SqlPipe p = SqlContext.Pipe;
p.Send(”Hello!”); - Now we can test out our new stored procedure by right-clicking on the project and selecting “Deploy”. This will create a DLL file and copy it over the SQL Server.
- Open up SQL Server Management Studio and click on the button titled “Create a New Query’. You should see a screen pop up on the right.
- Enter this code:
USE [YourDatabaseName]
GO
EXEC [dbo].[WhatYouNamedYourStoredProcedure]
GO - Now right-click in that code space and select “Execute”. If you experience this error: “Execution of user code in the .NET Framework is disabled. Enable “clr enabled” configuration option”, then execute the following query first:
sp_configure ‘clr enabled’, 1
go
reconfigure
go - You should see the text “Hello!” appearing in your output window
- To do something that’s actually useful, we can add in the following code to our stored procedure, which essentially selects all records in our database and outputs them:
SqlConnection conn = new SqlConnection(”Context Connection=true”);
SqlCommand cmd = new SqlCommand(@”SELECT * FROM YourTable”, conn);conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
SqlContext.Pipe.Send(rdr);rdr.Close();
conn.Close(); - Done! You have just created and run your first stored procedure. Wasn’t that easy?
Subscribe to my blog:
RSS reader
Email
Best Free Windows Calculator Replacement
Moffsoft FreeCalc is a freeware calculator application that is the best Windows calculator alternative. That’s right — you can completely replace the in-built calculator within Windows with this freeware tool because it provides so much more functionality.
Firstly, the calculator is resizable, so gone are the days that you had to carefully click on each number (yes, I know you can type it in on the keyboard as well). With Moffsoft FreeCalc, you can expand the calculator window so that it even fills up the entire screen if you wish! This makes pressing those buttons SO MUCH easier. Just check out a screenshot of it running on my laptop here:

Secondly, you get a useful tape (optional - can be turned off) that is displayed on the right of the main calculator window, and it’ll record down all the operations that you’ve performed.
Just these two additional features alone have made me switch from the calculator in Windows to this great little freeware application. Try it out! Moffsoft FreeCalc can be downloaded here. And if you want a premium version that comes with even more features (and I mean A LOT), then you’ll be pleased to know that Moffsoft offers a premium version of their calculator as well. Want even more calculator software? Then check out this site, because it offers a really wide range of freeware and software downloads.
Subscribe to my blog:
RSS reader
Email
How To Edit .htaccess So That SSI Include Code Will Run
If you have tried adding in SSI include codes into your HTML files, but find that it doesn’t work, the problem may be that you might not have enabled SSI yet.
The easier way to do so is to edit your .htaccess file to have these lines of code:
AddHandler server-parsed .html
Options Indexes FollowSymLinks Includes
By setting this, you are telling your server to parse all HTML files. There’s a drawback though — ALL HTML files are parsed — even if they don’t have SSI or include code in them. So, there’s a bit of an overhead. Otherwise, this is fine.
Subscribe to my blog:
RSS reader
Email
Best Free PHP Forum Script
The best PHP forum software has got to be vBulletin, because it has unparalleled features and support. The only problem is it costs over a hundred dollars. So that may be a problem if you’re just starting out.
It used to be that the single largest competitor to vBulletin was phpBB, but it’s no longer the case. Recently I discovered a few VERY good free php forum scripts. I’m really amazed by them because all these scripts are lightweight, elegant, and fast! If you are looking to start your own forum, then these are the best free forum scripts that you can find. In no order of preference, they are:
1. PunBB
2. Vanilla
3. BBPress
One thing that you MUST consider, however, is the future of your website. These relatively-new forum scripts have a rather different backend structure as compared to vBulletin — and looking through the current database importer scripts that vBulletin provides, only phpBB can be seamlessly imported into vBulletin with ease.
So if you’re looking to upgrade to something like vBulletin, then these forums might not be such a good idea. If you’d like something safer, go with phpBB. It’s free, it’s feature-packed, and it has a huge community that provides support and mods free. In fact, one hugely popular free mod for phpBB is a free WordPress and phpBB bridge plugin.
Subscribe to my blog:
RSS reader
Email
How to Learn and Use Regular Expressions (Regex)
Whoever would have thought that something that looks like gibberish would actually have such powerful usages. Look at this example:
\d\d[/]\d\d[/]\d\d[ ][-][ ]
Would you believe that it’s actually an expression that matches anything of the format of “12/06/08″? Amazing.
I’ve been putting off learning about regular expressions (regex) for the longest time because it seems overly complicated — but I was forced to learn more about it after a recent application demanded of it. And boy was I glad to have finally jumped into it — it’s simply one of the best ways to search for any text pattern.
With regular expressions, you can search for any number of characters, specify whether it’s a number or letter, and even specify a range, like only accept alphabets between B and E. Or only numbers from 1-5.
So if you think about it, the sample regular expression string up there can actually be improved upon. For instance, since the date format is dd/mm/yy, we know that dd can go higher than 31, nor can it go lower than 1. And similarly, we know that for mm, it’s between 01 to 12. The tricky part is yy, because it can vary, depending on how you’re going to use this date. If your application’s more geared towards the future, then keeping the first digit to 0 or 1, and the 2nd digit from 0 to 9 should be just fine.
So as you can see, if you’re a developer, then regular expressions (regex) should be something that you are very familiar and comfortable with, because it makes your life so much easier!
Subscribe to my blog:
RSS reader
Email
24 Jul 08 | 

