Monday, September 13, 2010

How to find Last index of character in SQL Server 2008


How to find Last index of character in SQL Server 2008

Many times we need last index of specific character in given string (file processing/name processing)
In SQL Server.
Below is the function for it. you just need to run below function in your sql server.
And need to pass to parameter .
1) @strChar= String from which you find the last index of some Character.
2) @strChar = string/Character


CREATE FUNCTION LastIndexOf
(@strValue VARCHAR(4000),
@strChar VARCHAR(50))
RETURNS INT
AS
BEGIN
DECLARE @index INT

SET @index = 0
WHILE CHARINDEX(@strChar, @strValue) > 0
BEGIN
SET @index = @index + CASE WHEN CHARINDEX(@strChar, @strValue) > 1
THEN
(LEN(@strValue) - LEN(SUBSTRING(@strValue,CHARINDEX(@strChar, @strValue) + LEN(@strChar),LEN(@strValue))))
ELSE
1
END
SET @strValue = SUBSTRING(@strValue,CHARINDEX(@strChar, @strValue) + len(@strChar),LEN(@strValue))
END
RETURN @index
END

==============================================

RUN BELOW QUERY will return 6.
select DBO.LastIndexOf('12345.wmv','.')

===========================================

Best way to display default image if specified image file is not found?



Best way to display default image if specified image file is not found?
Many times in grid/repeater or even in image display we have a problem if we don’t find any image related to that ID/Record and to replace “X” sign or image not found message we need to do programming but here is the
Quick solution which saves lot’s of your time and also your server processing time.

Just put following code in your in your image control.

onerror="this.onerror=null;this.src='Noview.jpg'"
Below is the full code for that


Above code first try to found image at “FullLocationImage”,but if it don’t find an image at specified path it will show “NoViewImage”

Thursday, August 19, 2010

INDIA V/S CHINA

Now days there are much more talks going regarding comparison between India and China.
I read a book Ragav Bahl's, which give me more clear idea regarding both countries. Below are some points from this book.

:: POINT 1 ::
In 2050, 300 million of China's 1.4 billion strong population will be over 65.By 2020, India will have a surplus of 47 million people of working age, the only major economy to do so.
:: POINT 2 ::
India's defence budget is $30 billion, as compared to China's defence spend of approx $200 billion a year.China consumes half the cement, a third of the steel and a quarter of the aluminum produced in the world.
:: POINT 3 ::
There are more than 100,000 Indian students in the US, closely followed by almost as many Chinese students.China claims that 120,000 sq km of land that India calls its, actually belongs to China.
:: POINT 4 ::
China and India added nearly half a trillion dollars to their combined GDP during the global recession.China spends an average of $1 billion a day on developing infrastructure.
:: POINT 5 ::
China today is investing nearly half its GDP; no other economy, at no other time in history, has invested capital on that scale.Nearly 58% of India's GDP is consumed by over a billion people, giving the country an organic strength.
:: POINT 6 ::
10 of the world's 30 fastest growing cities are in India; its urbanization rate at 30% is accelerating.With 350 million people proficient in English, India is the largest English-using country in the world.
:: POINT 7 ::
China has 13 times more people today than USA did in 1900, when it began its economic miracle.India is projected to be the world's third largest economy by 2050, behind USA and China.

:: POINT 8 ::
In 2009, China overtook the USA as the world's largest car market.India's GDP is now over $1 trillion; it is expected to double to $2 trillion by 2015.
:: POINT 9 ::
In the year 1600, China and India together accounted for more than 50% of the world's GDP.China successfully tested a nuclear device in 1964, ten years before India.

Tuesday, August 10, 2010

ModalPopup box Ajax Problem

Problem :
When you have two drop down (or any control) in ModalPopup box,
and by one's post back event you want another control's value need to bind or fill.
But if you are using ModalPopup box then there is two problem
1) SelectedIndexChanged event will not fire.
2) ModalPopup box Disappear.

Solution :
STEP 1:
Make your update pannel's update mode to conditional.
UpdateMode="Conditional"
STEP 2:
write down folloing JavaScript function in your page's Head section
function IndexChanged()
{
document.getElementById('<%= btnIndexChanged.ClientID %>').click();

}
STEP 3:
Make Dummy button and put it in below your drop down.


STEP 4 :
Write folloing code in your first drop down


STEP 5:
In your .CS code put folloing code
//CS Code
protected void drpGrade_SelectedIndexChanged(object sender, EventArgs e)
{
BindDrpFreind(Convert.ToInt32(drpGrade.SelectedValue));
mpAddFriend.Show();
}
Root Cause of Problem
ModalPopupBox is not able to capture postback event so we are calling one Javascript function and through that we call OnSelectedIndex changed of a drop down.
if you have any problem or query write me on viralpala@gmail.com


Monday, August 2, 2010

Response.redirect is giving error

If you are getting following error after Response.Redirect()
“Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack”
I have three solutions for this
1) You can use Response.Redirect(“xyz.aspx”,false);

Response.Redirect(String URL,EndResponse);

String URL : Name/URL of your page on which you want to transfer the execution
EndResponse :
if false it will not stop execution immediately but it will allowed page to complete it’s execution and then redirect it to specified your page

if true then it will stop execution and it might give you error.

If you don’t want to execute page and stop and want redirect immediately,
Use second solution.



You can put Response.Redirect() out side of you try catch block


Or Third Solution

Replace Response.Redirect() with folloing code.