Google like auto complete suggestions

Posted by Zafar Iqbal on Wednesday, June 11, 2008 - 01:05

I like Google’s suggest feature and was thinking of using it in any of my project. ASP.NET’s AJAX Control Toolkit have a similar control (AutoCompleteExtender) which provides a basic items to complete this functionality. I searched about its usage, and found many examples, but I was not satisfied with them. They all were populating only a single field using this extender.

I then came up with an idea, why not fill a contacts detail including its name, email address, and phone numbers using just one extender, but without modifying any provided functionality, so that our code be used with newer versions. Below is what it will look after populating that contact form.

contact

(Continue Reading …)

Rollover logging in database

Posted by Zafar Iqbal on Monday, June 02, 2008 - 23:50

We are currently working on an application (window service), which grabs alerts data from a third party web application and parses each alert and process its status, reasons, and source for different attributes and then creates tickets for support staff.

In this project we were logging all detail activities of parsing alerts into our database, which alert was raised, what was the source and IP Address and so on. Our service was grabbing data from that website after five minutes interval. There were nearly hundreds of alerts on each pass. So our log table was getting heavy each day.

(Continue Reading …)

Type.GetType()

Posted by Zafar Iqbal on Monday, May 26, 2008 - 23:33

Browsing through ASP.NET Forums, I found an interesting questions raised by a member that when he tried to get type information of a class using Type.GetType it was a charm in C#, but VB did not worked in same manners. He was trying to create new instances of that class at runtime, and populate those instances with data fetched from any database.

I checked its documentation in MSDN, here are its salient points, which should always be thought out before using this.

It accepts only a parameter which must contain an assembly qualified name of required type. This parameter could be only type name (i.e. "Contact") or may include namespace in it (i.e. "Hansvits.Models.Contact").

If parameter has only type name then method will search only in the assembly in which that call was made. If any full/partial assembly name is mentioned then it will load that assembly and search in it.

(Continue Reading …)

Using Boolean algebra in SQL

Posted by Zafar Iqbal on Friday, May 16, 2008 - 01:59

Recently I was working on a procedure which required that I marked some items in different categories, and then based on that marking we have to summarize items in different sections. I have extracted the main idea from this procedure for our example. It is using some Boolean algebra to segregate items into different sections.

(Continue Reading …)

Bucketing consecutive numbers in a range

Posted by Zafar Iqbal on Monday, May 12, 2008 - 02:17

Recently we had a little tricky problem to solve. We were displaying a report in which we had to bucket numbers in a range, such that only consecutive numbers should be in that range, if any break is there, then a new range should start. Our first solution did not worked as required. Most difficult part was identifying numbers in a sequence, and placing them in a bucket. We could not create any simple T-SQL queries which could easily sort these things out. Then we thought of first capturing the bucket of each number so that we can easily work it out, and that was not possible without cursors. Lets have a look how we did that.

(Continue Reading …)

Mod operator puzzle

Posted by Zafar Iqbal on Monday, May 12, 2008 - 01:12

Recently I saw a puzzle on SQL Server Central, I was intrigued to solve it myself, so here is what I was able to accomplish, and in less than 10 minutes.

DECLARE @i int
SET @i = 0

CREATE TABLE #X (val INT)

WHILE @i < 100
BEGIN
    SELECT @i = @i + 1
    INSERT INTO #X VALUES (@i)
END

SELECT val,
       val % 3,
       val % 5,
       CASE
            WHEN val % 3 = 0 AND val % 5 = 0 THEN 'BIZZBUZZ'
            WHEN val % 3 = 0 THEN 'BIZZ'
            WHEN val % 5 = 0 THEN 'BUZZ'
       END xval
FROM   #X

DROP TABLE #X

Ahsan’s second birthday

Posted by Zafar Iqbal on Tuesday, April 29, 2008 - 06:00

Ahsan - Shahi Masjid, Lahore Today we are celebrating birthday of my son Ahsan Zafar, many many happy wishes from me. I am a bit sorry that I would not be with him on this day. He is in Multan, with his grand parents. I think he enjoys their company, and loves to express himself and impose his tiny thoughts on them. He has that liberty with them, which I think we were denied. I don’t know why in our society people love their grand children more than their own. They are bit relaxed in this age, that may be a good reason for that. Anyhow I too enjoy time spent with them, always.

how div is drawn

Posted by Zafar Iqbal on Friday, August 31, 2007 - 00:36

In IE5 and IE6

  1. A div is rectangular.
  2. Only one corner of a div can be absolutely positioned on a page.
  3. The location of the diagonally opposing corner must be determined by the width and height of the div.
  4. The width and height can be determined using dynamic properties.

In all other browsers:

  1. A div is rectangular.
  2. All four corners of a div can be absolutely positioned on a page.
  3. If the location of diagonally opposing corners has been determined, the width and height is implied.

AJAX: selecting the framework that fits

Posted by Zafar Iqbal on Monday, May 14, 2007 - 21:42

Today I was just wandering on the net, and found a very good article on AJAX framework selection by Andrew Turner and Chao Wang.

See Details

Generate random number for each row

Posted by Zafar Iqbal on Thursday, February 15, 2007 - 19:33

Today I had to add a new date column to one of my table, and populate it with some random entries. I found a script from SQL Team Blog about generating random numbers. I modified it a little and used it to populate these dates based on another date I had in my table.

Here is modified code:

-- Create the variables for the random number generation
DECLARE @Upper int;
DECLARE @Lower int-- This will create a random number between 1 and 365
SET @Lower = 1 -- The lowest random number
SET @Upper = 365 -- The highest random number

-- we'll use this temp table to assign a random number to each ID value
CREATE TABLE #temp (ID int NOT NULL, RandNum float NULL)
INSERT #temp (ID) SELECT ID FROM FOO

-- now, assign a new random value to each key value in #temp
DECLARE @id int
DECLARE Randomizer CURSOR
FOR SELECT RandNum FROM #temp

OPEN Randomizer
FETCH NEXT FROM Randomizer INTO @id

WHILE @@Fetch_Status != -1
BEGIN
UPDATE #temp SET RandNum = rand()
WHERE CURRENT OF Randomizer

FETCH NEXT FROM Randomizer
END

CLOSE Randomizer
DEALLOCATE Randomizer

UPDATE F
SET F.NewDate = dateadd(dd, round((T.RandNum * 100), 0), F.AnyDate)
FROM
FOO F INNER JOIN #temp T ON F.ID = T.ID

DROP TABLE #temp