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

Monday, August 31, 2009

Windows User Control Load Event

H! All If you try to get Load event of Your windows User control you will surprised that you have no Load Event for The Control..

If you want to do something at the load of control then you all need to do is as follows...

Go to the Form where you have loaded your User Control. Click on to the User Control and see the events supported by it.

In the instance of this User Control you will find the LOAD event now write down your code at the event of it.

you can also access the control of your User Control by name instance name of User Control.

Friday, July 10, 2009

Define Custom masking on Masked Text box


Hello, Masked Text box is a very rich control available. you can restricted user input and provide format to enter data.

you just have to set masked text box property.

you can get that property dialog box from property window as well as from arrow at the top of text box.

there are many predefined formats are available and you can also set user defined custom format with the use of following table.

Masking element


Description



0


Digit, required. This element will accept any single digit between 0 and 9.



9


Digit or space, optional.



#


Digit or space, optional. If this position is blank in the mask, it will be rendered as a space in the Text property. Plus (+) and minus (-) signs are allowed.



L


Letter, required. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-zA-Z] in regular expressions.



?


Letter, optional. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-zA-Z]? in regular expressions.



&


Character, required. If the AsciiOnly property is set to true, this element behaves like the "L" element.



C


Character, optional. Any non-control character. If the AsciiOnly property is set to true, this element behaves like the "?" element.



A


Alphanumeric, optional. If the AsciiOnly property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z.



a


Alphanumeric, optional. If the AsciiOnly property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z.



.


Decimal placeholder. The actual display character used will be the decimal placeholder appropriate to the format provider, as determined by the control's FormatProvider property.



,


Thousands placeholder. The actual display character used will be the thousands placeholder appropriate to the format provider, as determined by the control's FormatProvider property.



:


Time separator. The actual display character used will be the time placeholder appropriate to the format provider, as determined by the control's FormatProvider property.



/


Date separator. The actual display character used will be the date placeholder appropriate to the format provider, as determined by the control's FormatProvider property.



$


Currency symbol. The actual character displayed will be the currency symbol appropriate to the format provider, as determined by the control's FormatProvider property.



<


Shift down. Converts all characters that follow to lowercase.



>


Shift up. Converts all characters that follow to uppercase.



|


Disable a previous shift up or shift down.



\


Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.



All other characters


Literals. All non-mask elements will appear as themselves within MaskedTextBox. Literals always occupy a static position in the mask at run time, and cannot be moved or deleted by the user.


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;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO

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.


SELECT *
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?

Hello,

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
ADD CityId INT
CONSTRAINT Fk_tblEmployee_tlkpCity
FOREIGN KEY (CityId)
REFERENCES tlkpCity(lkpTypeId)

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

Tuesday, April 28, 2009

Add new Line Character in Vb.net String.

While we want new line in C# we just use "\n" but if you use this in vb.net you will not get the desired result. Vb.net is bit a different then others you have some other choice to do this...

For new line character you can use one of following items..

VB Constants: vbNewLine, vbCrLf
Character Function:
Chr(13)
VB Control Chars:
ControlChars.NewLine, ControlChars.CrLf
Environment Variable:
Environment.NewLine