Advertisement

07.08.2008 at 03:20PM PDT, ID: 23548527
[x]
Attachment Details

catching null reference exception

Asked by DancingFighterG in .NET, Programming for ASP.NET

Hello, I'm trying to catch an null ref exception if the url that the page that enter in does not exist. here is my code:

  if (sName.Length > 0)
            {
                //Get Id From Name            
                sId = ((Int32)db.ExecuteScalar(db.GetSqlStringCommand("Select Id From v_Navigation Where Name = '" + sName.Replace("|", "").Replace("'", "''") + "'"))).ToString();
            }

If Id does not exist it will throw an error but I want to redirect to the home page. I want to use a try catch but I don't know where to put it.Start Free Trial
[+][-]07.08.2008 at 03:30PM PDT, ID: 21958894

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 10:02PM PDT, ID: 21960716

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, Programming for ASP.NET
Sign Up Now!
Solution Provided By: renjurdevan
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.09.2008 at 04:12AM PDT, ID: 21962268

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628