Friday, December 26, 2008

VB.net SQL statement for SELECT * WHERE mydate = ?

It is sometimes frustrating to find out that the date function is not working correctly when you are trying to retrieve date from the database in vb.net with Access database. I tried to get the data for nearly two days but failed to get it.

The answer to that was very simple

In Access Database, make sure that the date field is set to Short Date and the Format is "dd/mm/yyyy" or what ever you like.

Then use your normal SQL statement for date and it will work

I have used the following

SELECT * FROM tbl_Student WHERE Enroll_Date = #" & me.cboEnrollDate & "#"

Wednesday, December 24, 2008

How to write Connection String for VB.net and ADO

Ever since I am writing my programs, I have delt with databases. The one big thing to protect the user to inadvertently changing the database by opening it and changing something is one of the nightmares all software programmers face.

To tackle this, for Microsoft (R) Access database, we password protect the database. I will not go in details on how to password protect Access database (as this can be another blog in itself), I will show how to open such password protected Access databases through VB.net

Use following connection string to open the normal database

Public ConString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & Application.StartupPath & "\MyDatabase.mdb"

Use following connection string to open a Password protected database

Public ConString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & Application.StartupPath & "\MyDatabase.mdb;Jet OLEDB:Database Password = " & PassWD & " "

Where PassWD is a string constant stored somewhere in the program

I hope this will help someone doing database programming and forgotten how to open a password protected database through VB.net

Thursday, December 18, 2008

Merry Christmas - Monkey wants Banana

I received this email when I was in India working for an international organisation and thought it only happened in India, but I was wrong. The story goes like this

Put 7 monkeys (not more not less) in a room. This room has a ladder in the centre and 7 bananas (one for each monkey) on top of the ladder. There are other fruits like mangoes, apples, grapes etc on the ground in abundance. Intelligent Monkeys (oops Humans) are watching what the monkeys are doing from a silver glazed glass window which allows humans to watch monkeys but monkeys can’t see humans.

The rules are:

  1. To get the bananas, monkey has to climb up the ladder and grab it.
  2. As soon as one monkey tries to climb up the ladder, other 6 monkeys get sprayed with ice water. The water is so freezing that the 6 monkeys start screaming and running around
  3. Monkeys can eat any fruit that is lying on the ground but as soon as one tries to get the bananas, others are sprayed with ice water.

After some time monkeys figured out that as soon as some one tries to grab the banana others are sprayed. Instead of thinking of “How to get the bananas”, monkeys make a deal in which who so ever tries to climb up the ladder, others will beat him.

This goes on for some time and, as one monkey tries to climb up the ladder (as the temptation of banana is too big), others fearing that they will be sprayed, they start beating the one trying to climb the ladder.

Now remove 1 monkey from the group of 7 and put a new monkey in.

This new monkey not knowing any rules and deals sees the bananas and tries to get up the ladder, others seeing that the new one is getting up the ladder start beating him (even though they are not sprayed with cold water). The new monkey thinks that it might be a custom to beat someone who tries to go up the ladder.

Now remove another old monkey and put a new one, so there are 2 new and 5 old monkeys.

When the second new monkey tries to go up the ladder, other 6 including the one that was replaced first starts beating the new one. As it is a custom now, slowly and slowly everyone forgets the deal.

Now, slowly and slowly, one by one, remove all the old monkeys and put new monkeys in.

What happens NOW is that whenever any of the monkeys climb up the ladder (because of the temptation) others beat him thinking that it’s a custom of the room not knowing the real deal behind the beating.

In life the story is not different, especially in the corporate world.

Merry Christmas

Thursday, December 11, 2008

Grass is always green on your side

Who doesn’t like their lawn look healthy and green all year long. If you follow these simple steps the statement “Grass is always green on the other side” will be true for your neighbors.

To keep your lawn healthy and green feed them with chook (chicken) manure once a year. Chook manure is really smelly so be prepared to take that strong puff of odor when you are sprinkling it in your lawn. Take a handful and throw it on the ground liberally.

Marketing by Imperessive Reports

I had to give a small printout to our family friend which contained a casual market research that I did for him. I had jotted some points down for him stating what the purpose of the research was, what I found and what can be done to change to existing situation. The report was just 5 pages long. He is not the person who will want to read a lot and he just needs results. After printing them for him, I used a translucent plastic clip file and gave it to him. When he saw the report given in such a format he was really happy and appreciated the work I had put in to generate the report.

The work done to get the data remains same whether I would have given him a report as loose papers or as I did by giving a proper file.

Make usb storage disk recognisable by Windows XP

Sometimes your computer refuses to recognise usb flash disks or portable hard disk. I had this problem when I tried to connect my 160GB Western digital portable hard disk to my work computer. I could connect my 1GB usb flash disks and my computer would recognise it but not my portable hard disk. I thought that my company would have set rules on the size of hard disk that you can connect to the computer. One of my work mates told me to check the disk management and see if my hard disk is there. When I saw my hard disk listed there, I was confused. Then he told me to assign a different drive letter to my hard disk. When I did this my computer recognised my portable hard disk and I was able to access the files and folders in them.

Headings in Word 2003 and Word 2007

To quickly change the normal text in Word 1003 and 2007 to Heading 1 use Ctrl+Alt+1, to change to Heading 2 use Ctrl+Alt+2 and to change to Heading 3 use Ctrl+Alt+3 and so on.

This short-cut will help you to change the text to Heading without going into all the menus or use the Ribbon Bar.