In one of my project there was an requirement to display the Phone Numbers formatted according to US Standards(eg: 123-456-7890).
I initially thought I have to insert the '-' symbol at the index values. But my goodness, this was made so easy in .Net String Formatting.
For Example:
Dim phone as Integer = 123456890
String.Format("{0:###-###-####}", phone)
This will be displayed as 123-456-7890
Be a smart coder. Let me know if its useful. Happy Coding.
Friday, September 25, 2009
Wednesday, September 2, 2009
Reseed Identity Column in a Table
Today in our web application we have to make a major release to production. Everything went fine but we have lot of test entries in the production. Our identity column of the User table increased from 1342 to 1456 because of the test entries. Myself and a friend of mine read an article for resetting the Identity Column. So after deleting the entries this is what you have to do.
Resetting Current Identity Value to New Value
Resetting Current Identity Value to New Value
use DBNAME
go
dbcc checkident(TABLENAME, reseed,seed value)
For Eg:
dbcc checkident(dbo.[User],reseed,1342)
which served my purpose.
To Get Current Identity Value
Also this seems to be useful. This gives the current identity value of the table.
use DBNAME
go
dbcc checkident(TABLENAME, noreseed)
For Eg:
dbcc checkident(dbo.[User],noreseed)
Please let me know your thoughts. Have a good day.
Saturday, August 29, 2009
Basic SQL System Stored Procedures to be known by every Developer
There are large number of System Stored Procedures. Here are few stored procedures that should be known by every developer who work with Databases. And these stored procedures will be very handy at times(Particularly for me.My favorites :) ).
sp_Help:
Gives the structure of the table.
Syntax: sp_Help
Eg: sp_Help 'dbo.tblProduct'
sp_Helptext:
Gives the definition of the objects like Stored Procedures(both user defined and system defined), Triggers, Functions and etc.
Syntax: sp_Helptext
Eg: sp_Helptext 'dbo.sp_tblProduct_Insert'
sp_Depends:
Gives all the Stored Procedure and View associated with the Table.
Syntax: sp_Depends
Eg: sp_Depends 'dbo.tblProduct'
sp_Spaceused:
sp_Help:
Gives the structure of the table.
Syntax: sp_Help
Eg: sp_Help 'dbo.tblProduct'
sp_Helptext:
Gives the definition of the objects like Stored Procedures(both user defined and system defined), Triggers, Functions and etc.
Syntax: sp_Helptext
Eg: sp_Helptext 'dbo.sp_tblProduct_Insert'
sp_Depends:
Gives all the Stored Procedure and View associated with the Table.
Syntax: sp_Depends
Eg: sp_Depends 'dbo.tblProduct'
sp_Spaceused:
Gives information on the size database objects.
Syntax: sp_Spaceused
Eg: sp_Spaceused 'dbo.tblProduct'
I can assure you these System Stored Procedures will help you in Development.
Please let me know your thoughts. Have a wonderful time.
Thursday, August 27, 2009
Change Focus for TextBoxes using Javascript
In most of the real time project there will be requirement to change focus of the TextBox from one to another dynamically, instead of clicking the TextBoxes. The ideal example in this case would be Phone Number Text Boxes in the US format(000-000-0000). Consider there were three TextBoxes. It wil be irritating for the end user to click each text box and then type numbers.
So here, on every keyboard press event ("onkeypress") we capture the event and check for the length of the TextBox in the changeFocus() Javascript function. Again the browser compatibility issue raises its head and its handled in its own way. This is so simple to implement. Here is the code snippet.
Javascript Function:
//Change Focus for the Phone TextBox
function changeFocus(textbox1,textbox2)
{
var browserName=navigator.appName;
if (browserName=="Netscape")
{
if(textbox1.value.length >= 2)
{
textbox2.focus();
}
}
else if(browserName=="Microsoft Internet Explorer")
{
if(textbox1.value.length == 3)
{
textbox2.focus();
}
}
else
{
if(textbox1.value.length == 3)
{
textbox2.focus();
}
}
return true;
}
//End of Change Focus for the Phone TextBox
The ASP.NET(Vb) File Code:-
You can add this code in the Load Event of the Page.
Me.TxtCellPhone1.Attributes.Add("onkeypress", String.Format("javascript:return changeFocus({0},{1});", Me.TxtCellPhone1.ClientID, Me.TxtCellPhone2.ClientID))
Me.TxtCellPhone2.Attributes.Add("onkeypress", String.Format("javascript:return changeFocus({0},{1});", Me.TxtCellPhone2.ClientID, Me.TxtCellPhone3.ClientID))
Here no need to add an event for TxtCellPhone3 TextBox.
Let me know your Thoughts. Happy Coding.
So here, on every keyboard press event ("onkeypress") we capture the event and check for the length of the TextBox in the changeFocus() Javascript function. Again the browser compatibility issue raises its head and its handled in its own way. This is so simple to implement. Here is the code snippet.
Javascript Function:
//Change Focus for the Phone TextBox
function changeFocus(textbox1,textbox2)
{
var browserName=navigator.appName;
if (browserName=="Netscape")
{
if(textbox1.value.length >= 2)
{
textbox2.focus();
}
}
else if(browserName=="Microsoft Internet Explorer")
{
if(textbox1.value.length == 3)
{
textbox2.focus();
}
}
else
{
if(textbox1.value.length == 3)
{
textbox2.focus();
}
}
return true;
}
//End of Change Focus for the Phone TextBox
The ASP.NET(Vb) File Code:-
You can add this code in the Load Event of the Page.
Me.TxtCellPhone1.Attributes.Add("onkeypress", String.Format("javascript:return changeFocus({0},{1});", Me.TxtCellPhone1.ClientID, Me.TxtCellPhone2.ClientID))
Me.TxtCellPhone2.Attributes.Add("onkeypress", String.Format("javascript:return changeFocus({0},{1});", Me.TxtCellPhone2.ClientID, Me.TxtCellPhone3.ClientID))
Here no need to add an event for TxtCellPhone3 TextBox.
Let me know your Thoughts. Happy Coding.
Tuesday, August 25, 2009
Diable Browser Back Button
I have gone mad for getting my browser back button disabled in one of my projects. And at last arrived at this solution:
function disableBrowserBackBtn() { window.history.go(1) }
disableBrowserBackBtn();
window.onload = disableBrowserBackBtn();
window.onpageshow = function(evt) { if (evt.persisted) disableBrowserBackBtn() }
window.onunload = function() { void (0); disableBrowserBackBtn(); }
You have to just add the Script in the pages you want to disable the browser back button.
But this is just bluffing the user, using the the javascript code window.hsitory.go(-1) ->Redirecting to previous page.
For the perfect solution you have to open a new pop-up window with no navigation toolbar.
Please let me know your comments....Have a good day.
function disableBrowserBackBtn() { window.history.go(1) }
disableBrowserBackBtn();
window.onload = disableBrowserBackBtn();
window.onpageshow = function(evt) { if (evt.persisted) disableBrowserBackBtn() }
window.onunload = function() { void (0); disableBrowserBackBtn(); }
You have to just add the Script in the pages you want to disable the browser back button.
But this is just bluffing the user, using the the javascript code window.hsitory.go(-1) ->Redirecting to previous page.
For the perfect solution you have to open a new pop-up window with no navigation toolbar.
Please let me know your comments....Have a good day.
Subscribe to:
Posts (Atom)