Limit the text returned from a field using SQL

In most databases today there are columns that contain thousands of characters of text. In some cases this information needs to be returned to an end user on a busy section of your site, for example a search feature.

If someone does a search on your site usually you will be displaying only a portion of that content when displaying the search results. You could very easily return the full content of all your columns to the end user and use your code to stip off the excess data but a much faster way is to strip off what you don't need in SQL before you pass back to your code. One way of doing this is to use the SubString method in SQL Server:

SUBSTRING(ColumnName, start position, end position)

Example below returns the value within PostDetails from the start position up to 150 characters long and calls this new 'field' PostSummary

SUBSTRING(PostDetails,1,150) as PostSummary

Full example:

Select PosterName, PostDate, SUBSTRING(PostDetails,1,150) as PostSummary
From Posts
Where <<search conditions entered from search page>>

You can easily call PostSummary just like you call PosterName or PostDate in your code view.

Dec02

News Flash - escape key has finally done it!

Today's Friday Funny:

Dynamically set the Body Onload attribute when using MasterPages

If you use MasterPages in your .Net website there will be a time when you want to load some javascript on a certain page and have it called OnLoad within the Body tag. A good example is when you use Google Maps.

When setting up your Google Map you will need to place javascript in the header of your page and you also need to set the Body OnLoad and UnLoad attributes. You could place the javascript in the MasterPage and be done with it but that is such a waste as usually you only want the Map to show on a contact page or similar. So how do you set the onBody attribute from within a child page?
More...

Nov28

updating iPhone from 1.1.4 to 2.2

iphone running 2.2

The new pwnage tool for iPhone 2.2 was released and it works perfectly for me. I was running 1.1.4 on a jailbroken iPhone and was able to upgrade to 2.2 without any problems at all. Just followed the detailed instructions from iClarified - http://www.iclarified.com/entry/index.php?enid=1880 - and everything should be super smooth for you. Basically you will need to do the following:

  • sync to save all your contact info.
  • download the latest firmware through iTunes.
  • install it on the iPhone.
  • run the pwnage tool.

This tool will jailbrake your iPhone and allow you run on any phone network if you select the JailBrake option. Once you have that part completed you can do a Restore in iTunes and all your contacts, photos, SMS's and music will be reloaded for you. I'm running my iPhone on Meteor's network in Ireland and it's working great.

You should allow yourself around 30mins to an hour to do the upgrade as it does take a bit of time to run.

[UPDATE] I have a new post about upgrading from ver 2.2 to 3.0 here.

Nov23

how to read data from an Excelsheet using C#

I had to use the script below to read in values from an Excel sheet using C# recently. The script itself is generic enough but it has one benefit - you don't need to know the name of the sheet you want to import. This can be very beneficial if you have people supplying you with Excel sheets as everyone has their own way of saving sheet names.

The code in this example will take your Excel sheet and read in the first 5 columns. It will also loop through any other sheet and read in the first 5 columns in those too.
More...

Nov18

How to host a domain that is not in your GoDaddy account

*This article was previously posted on my old blog but I get a lot of traffic to the site about this topic so I have decided to put it back online. Hope it helps you out it you're stuck!*

I recently had to setup external domain in my GoDaddy account as one of my clients had already purchased their domain name before getting me to do some work for them. I couldn’t transfer the domain as it was within 60 days of being registered so the only option I had was to change to NameServers and point the domain to my account. So how do you do this? Read on ;)

For this exercise we are going to be repointing a domain called repointingdomain.com. Be sure to change that domain to whatever it is that you’re using when setting this up on your GoDaddy.com
More...

Nov17

EasyHouseExchange.com is live

Easy House Exchange

It's been a tough few weeks but we've finally launched our newest creation - EasyHouseExchange.com. From a technical point of view it is one of the most advanced sites I've had to create while working in Dragnet. The site features a really cool image upload and resize tool with progress bar, simple to use layouts and forms, a nifty site tour guide, a bulk import tool for external developers so they can put up hundreds of properties online for their account in seconds and little sprinklings of AJAX thrown in for good measure.

To kick off the site we have Bovis Homes in the UK giving us hundreds of properties from all over the UK and we have a bunch of Irish and UK developer's properties that are being uploaded over the next few weeks so it's all exciting stuff for us. Our PR guys are working hard to get the press releases done and we should see the site in a few of the well established Sunday papers and talked about on radio shows over the coming weeks.

As is always the case, there were a few things that we wanted to include but we had to cut to make our release date but we will be working hard to include these features as time moves on. So, take a look at the site and let me know what you think, whether it's good or bad I don't mind. All feedback is greatly appreciated and all comments are taken on board.

Nov11

EasyHouseExchange.com launching very soon

EasyHouseExchange.com

One of my latest projects, easyhouseexchange.com, is set to launch very soon. We are in the final stages of testing the site for its launch which should be happening end of next week (Nov. 7) all going well.

This site is designed to let individuals, investors and developers put their houses online and swap them with other home owners who want to trade up or down the property ladder. All users are required to sign up and upload their property before they can contact another home owner on the site. An individual can only upload one house but a developer can upload up to 10 properties per development and an investor can upload up to 10 properties. Breaking the sign up process into these areas has allowed us to come up with a very attractive and competitive pricing structure for this site.

The home page features a really nice scroller of the latest houses uploaded. Users can click on any of these properties they might be interested in our they can use our simple (and yet incredibly complex behind the scenes) search facility that allows them to narrow their search to find the perfect home.

As always, the best part of any site build is the launch and I'm really excited about launching this site. It's always great to see how people play with your sites, getting feedback and making the little tweaks that help make the end result better than anything else out there! Fingers crossed it will all go well for us now.

Oct31

How to know which button is clicked on when using a repeater C#

If you're developing websites, sooner or later you will be asked to produce a list of data where each row will need to have a button on it that performs a function. If you need to do this in a Repeater and are wondering how to achieve this then read on.

For this example I will assume you know what a repeater is and are familiar with how to binding data to it from a database or similar.

In your .aspx page you would have a repeater. Below is a sample that I'm going to use for this example:

<asp:Repeater ID="MyRepeater" OnItemCommand="WhatToDo_ItemCommand" runat="server">
<ItemTemplate>
<ul>
    <li><%# Eval("ItemName")%></li>
    <li><%# Eval("ItemDetails")%></li>
    <li><asp:LinkButton ID="DeleteItem" CommandArgument='<%# Eval("ItemID") %>' CommandName="DeleteThisItem" runat="server">delete this item</asp:LinkButton></li>
    <li><asp:LinkButton ID="UpdateItem" CommandArgument='<%# Eval("ItemID") %>' CommandName="UpdateThisItem" runat="server">update this item</asp:LinkButton></li>
</ul>
</ItemTemplate>
</asp:Repeater>

Nothing to out of the ordinary here. There are a few things to note. In your <asp:repeater> tag you must include the class you want to call when the button is clicked. This is the OnItemCommand="WhatToDo_ItemCommand" bit. You will see in a few mins where this is used. Next up is the code that puts the ID value into the buttons you're going to use. CommandArgument holds the value for your command, in this case it's going to hold our database row ID and CommandName is needed so that our code will know which button made the call.

Next up is the code behind page:More...

Oct30

www.localhost.com is displayed when trying to debug in Visual Studio

Visual Studio Debug Issue

I posted about this issue in the previous version of my blog but I came up against it recently on my new home PC so I thought I'd blog about it again, if only so I can check this out the next time it happens to me.

Problem: Visual Studio 2008 incorrectly defaults to showing the url www.localhost.com when opening a browser for debugging which stops your page from loading.

Solution: You can type in your local home IP address - 127.0.0.1 - in place of www.localhost.com Visual Studio put in the browser URL but this means that you have to wait for ages for the browser to stop searching for www.localhost.com before it will let you type this in. What you should do is locate the following file:

C:\Windows\System32\drivers\etc\hosts

Open it in Notepade and remove the line that says

::1             localhost

If you can't overwrite the existing file because of Vista's UAC then save to your desktop as a txt. Once saved, knock off the .txt part of the filename you just saved and then copy and paste the file into the Windows\System32\drivers\etc. Click Yes to overwrite the existing file. Your debugged site will now show up with the correct address. Easy when you know how....I won't say how long I was looking for that solution!