this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Thursday, June 25, 2009

Show tooltip on Windows Controls..

It has been happen that we have some value in text box and dropdown box but we have not that much of space to show all text resides in it.

In those situation we can show whole text by tooltip. We all are familiar with tool tip. In windows operating system when you are going to click on some folder or just move your cursor on it. you would get info of that item.

you can use this in your application too..

.Net provides ToolTip control. with it use you can do that in very less time quickly.

Steps are as follows.

1) Add ToolTip control to your form (just drag from Tool box)

2) Now choose on which control you want to see tool tip.(Either text box,Radio button any controls you have on your form)

3)Go to the events of your control.

Now you have two events MouseHover and MouseMove.

MouseHover -It will be fired when your cursor resides to control for some amount of time.

MouseMove-It always fire when your cursor moving on control.

In that event write as..

ToolTip.SetToolTip(yourcontrolname,"Text you want to display")

ToolTip.Active = True

This will show "Text you want to dispaly" Tooltip when you move your cursor to that control. You don't need to create as many tool tip as all controls on which you want to show.

This one tool tip will do all for you. You just need to set control and tooltip text on the event of control.

Tuesday, June 23, 2009

Import Data from EXcel Sheet to SQL Server

To get the data from Excel sheet to SQL Server we can use many of SQL server services.
Before we import data using Excel Sheet ..We have to reconfigure our service with below queries..

EXEC sp_configure 'show advanced options', 1;
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;

Below query will return data from your Excel file and sheet1.
some of the attributes we have used "Microsoft.Jet.OLEDB.4.0" it is driver name. and spcify Excel 8.0.

In database we have specified our file path.

In that HDR specifies that whether our excel sheet can treat first row as Header or not. If we have set it to NO then OLEDB provider assign Column Names F1 to Fn. Same thing will happen if we have not included HDR in our connection string.

In Excel sheet it is possible that column have mixed data type. By default OLEDB provider see the column's value and then depending upon it defined datatype on that column.

If column have numeric value then it will omit anyother value in column and set null for other values.To over come this problem we can use IMEX attribute which brings all data regardless of its type.

If we have set IMEX we will have all data as we have in Excel sheet.

FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\testImport.xls;HDR=No;IMEX=1',
'SELECT * FROM [Sheet1$]')

Disable Right click Context menu on Web Page

There are some situation when we want to hide our source code from user. User can easily see your web page source code by right click on page.

There are so many scripts available to disable right click. you can even open context menu by keyboard.

This is some what easy and hands on attribute to disable right click

Just write..

oncontextmenu=”return false;” in body tag...

This will not allow user to open context menu by key board or by mouse. Just try it..

Monday, June 8, 2009

How to add Foreignkey Constraints to table?


Some time we want to add foreign key constraints to table with out being open up table structure.

This is some useful syntax to add foreign key constraints while we are going to add any new column to table.

ALTER TABLE tblEmployee
CONSTRAINT Fk_tblEmployee_tlkpCity
REFERENCES tlkpCity(lkpTypeId)

Here we have tblEmployee , we want to add new cityId column and this will be foreign key for table tlkpCity.