Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Wednesday, March 21, 2012

Please Help me

Below code is giving me error like ''function doesnt return in all code paths A null reference exception could occur"

As i m new to this tech i am not getting that

PublicSharedFunction getLookupCampusList(ByVal eidAsString, _

ByVal isAdminAsBoolean)As SqlDataReader

'Dim getLookup As SqlDataReader = Nothing

Dim paraValueAsObject() = {eid}

Dim myRoleAsString = appRole(eid)

If isAdminThen

If myRole ="A"Then

Try

Return SQLHelper.ExecuteReader("sp_locationDes", paraValue)

Catch exAs Exception

Throw ex

EndTry

ElseIf myRole ="E"Then

Try

Return SQLHelper.ExecuteReader("sp_GetUsingCommonDB", paraValue)

Catch exAs Exception

Throw ex

EndTry

ElseIf myRole ="B"Then

Try

Return SQLHelper.ExecuteReader("sp_getByEmpLoc", paraValue)

Catch exAs Exception

Throw ex

EndTry

EndIf

Else

Try

Return SQLHelper.ExecuteReader("sp_GetEmpID", paraValue)

Catch exAs Exception

Throw ex

EndTry

EndIf

End Function

If you indent your code to highlight the control-flow, logic errors become easier to find.

This error means that the compiler found a logic path that did not make use of a return statement.

If a function says it returns a given object type, unless it exits via an unhandled exception, it must return that object type.

If isAdminThen
If myRole ="A"Then
Return SQLHelper.ExecuteReader("sp_locationDes", paraValue)
ElseIf myRole ="E"Then
Return SQLHelper.ExecuteReader("sp_GetUsingCommonDB", paraValue)
ElseIf myRole ="B"Then
Return SQLHelper.ExecuteReader("sp_getByEmpLoc", paraValue)
EndIf
Else
Return SQLHelper.ExecuteReader("sp_GetEmpID", paraValue)
EndIf

I removed your try-catch commands for two reasons. The first reason was to make the above code snippet easier to read.

What will be returned if isAdmin is true and myRole = "NotInThisList"?

And if you say to yourself, but, "NotInThisList" isn't a valid value for myRole, remember that the compiler does not know that. :)

So, you need to add a logic path to handle some myRole value other than A, E, or B, or you need to change the ElseIf on "B" to be an Else.

The second reason I removed your try catch commands were that they were redundant. They did nothing but catch an exception and re-throw it.

If you never bothered to do that you would get the same result - an exception that needs to be handled by the calling routine. So, either add useful code that fixes the exception or logs it into your catch block, or don't bother to put them in.


Thanks Alot Its working


Glad it helped! Now you need to mark the answer so others don't wander in here to help you when you no longer need it. :)

Please help me how to call this Javascript

Hi,
Below is the Javascript function that am trying to call from asp:Button
control.
<script language="javascript">
function ValidateDate(fromDate,toDate)
{
var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}
if( diffDate > 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}
return true; //allow submit
}
</script>
In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");
But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.
Thanks,
VishnuTry this
btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");
settyv@.gmail.com wrote:
> Hi,
> Below is the Javascript function that am trying to call from asp:Button
> control.
> <script language="javascript">
> function ValidateDate(fromDate,toDate)
> {
> var fromDate=new Date();
> var toDate=new Date();
> var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
> alert(diffDate);
> if( diffDate < 0 )
> {
> alert( "The start date cannot be after the end date!")
> return false;
> }
> if( diffDate > 30 )
> {
> alert( "Please enter dates less than 31 days apart" )
> return false;
> }
> return true; //allow submit
> }
> </script>
>
> In code-behind am calling the function like as below:
> btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
> txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");
>
> But if start entering the dates,it submits the page as it takes both
> datee as current dates.Please let me know the reason.
> Thanks,
> Vishnu
Hi,
It is not working .it is telling script error.Here is the HTML created
after the postback.Everything is fine.But i dont know why it is telling
error.
Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
is null or not an object
<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><input type="submit" name="btnSubmit" value="Submit"
id="btnSubmit" onClick="return
ValidateDate(document.getElementById["txtFromDate"].Value,document.getElemen
tById["txtToDate"].Value);"
/></TD>
</TR>
Please let me know how can i solve this.
Thanks,
Vishnu
rampabbaraju@.gmail.com wrote:
> Try this
> btnSubmit.Attributes.Add("onClick"," return
> ValidateDate(document.GetElementById('" +
> txtFromDate.ClentId() + ').Value",document.GetElementById('" +
> txtToDate.ClentId()+ "'));");
>
> settyv@.gmail.com wrote:
Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD
"settyv@.gmail.com" wrote:

> Hi,
> It is not working .it is telling script error.Here is the HTML created
> after the postback.Everything is fine.But i dont know why it is telling
> error.
> Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
> is null or not an object
> <TR vAlign="top">
> <TD colSpan="4" height="25"></TD>
> <TD><input type="submit" name="btnSubmit" value="Submit"
> id="btnSubmit" onClick="return
> ValidateDate(document.getElementById["txtFromDate"].Value,document.getElem
entById["txtToDate"].Value);"
> /></TD>
> </TR>
> Please let me know how can i solve this.
>
> Thanks,
> Vishnu
> rampabbaraju@.gmail.com wrote:
>
Hi,
Here is the ASPX code.
<body ms_positioning="gridlayout">
<TABLE height="471" cellSpacing="0" cellPadding="0" width="174"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="174" height="471">
<form id="form1" runat="server">
<TABLE height="157" cellSpacing="0" cellPadding="0" width="459"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD colSpan="3" height="1"></TD>
<TD colSpan="2" rowSpan="2"><asp:textbox id="txtToDate"
runat="server"></asp:textbox></TD>
</TR>
<TR vAlign="top">
<TD height="38"></TD>
<TD colSpan="2"><asp:label id="lblFDate" runat="server"
Width="87px">From Date:</asp:label></TD>
</TR>
<TR vAlign="top">
<TD colSpan="2" height="1"></TD>
<TD colSpan="3" rowSpan="2"><asp:textbox id="txtFromDate"
runat="server"></asp:textbox></TD>
</TR>
<TR vAlign="top">
<TD height="41"></TD>
<TD><asp:label id="lblTDate" runat="server" Width="83px">To
Date:</asp:label></TD>
</TR>
<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><asp:button id="btnSubmit" runat="server"
Text="Submit"></asp:button></TD>
</TR>
</TABLE>
</form>
</TD>
</TR>
</TABLE>
</body>
And am trying to call the javascript that i sent earlier in code-behind
as shown below:
btnSubmit.Attributes.Add("onClick","return
ValidateDate(document.form1.elements['" + txtFromDate.ClientID +
"'].value,document.form1.elements['"
+ txtToDate.ClientID + "'].value);");
Now the problem is that am not able to see alert msg saying that the
difference is 0 ,which takes both dates as current date and it returns
the difference as 0. Please let me know how can i solve this issue.
Thanks,
Vishnu
Milosz Skalecki wrote:
> Show us more code (espacially text boxes declaration)
> --
> Milosz Skalecki
> MCP, MCAD
>
> "settyv@.gmail.com" wrote:
>

Please help me how to call this Javascript

Hi,

Below is the Javascript function that am trying to call from asp:Button
control.

<script language="javascript">
function ValidateDate(fromDate,toDate)
{

var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}

if( diffDate 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}

return true; //allow submit
}
</script>

In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");

But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.

Thanks,
VishnuTry this

btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");

settyv@.gmail.com wrote:

Quote:

Originally Posted by

Hi,
>
Below is the Javascript function that am trying to call from asp:Button
control.
>
<script language="javascript">
function ValidateDate(fromDate,toDate)
{
>
var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}
>
if( diffDate 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}
>
return true; //allow submit
}
</script>
>
>
In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");
>
>
>
But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.
>
Thanks,
Vishnu


Hi,

It is not working .it is telling script error.Here is the HTML created
after the postback.Everything is fine.But i dont know why it is telling
error.

Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
is null or not an object

<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><input type="submit" name="btnSubmit" value="Submit"
id="btnSubmit" onClick="return
ValidateDate(document.getElementById["txtFromDate"].Value,document.getElementById["txtToDate"].Value);"
/></TD>
</TR>

Please let me know how can i solve this.

Thanks,
Vishnu

rampabbaraju@.gmail.com wrote:

Quote:

Originally Posted by

Try this
>
btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");
>
>
>
settyv@.gmail.com wrote:

Quote:

Originally Posted by

Hi,

Below is the Javascript function that am trying to call from asp:Button
control.

<script language="javascript">
function ValidateDate(fromDate,toDate)
{

var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}

if( diffDate 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}

return true; //allow submit
}
</script>

In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");

But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.

Thanks,
Vishnu


Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD

"settyv@.gmail.com" wrote:

Quote:

Originally Posted by

Hi,
>
It is not working .it is telling script error.Here is the HTML created
after the postback.Everything is fine.But i dont know why it is telling
error.
>
Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
is null or not an object
>
<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><input type="submit" name="btnSubmit" value="Submit"
id="btnSubmit" onClick="return
ValidateDate(document.getElementById["txtFromDate"].Value,document.getElementById["txtToDate"].Value);"
/></TD>
</TR>
>
Please let me know how can i solve this.
>
>
Thanks,
Vishnu
>
rampabbaraju@.gmail.com wrote:

Quote:

Originally Posted by

Try this

btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");

settyv@.gmail.com wrote:

Quote:

Originally Posted by

Hi,
>
Below is the Javascript function that am trying to call from asp:Button
control.
>
<script language="javascript">
function ValidateDate(fromDate,toDate)
{
>
var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}
>
if( diffDate 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}
>
return true; //allow submit
}
</script>
>
>
In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");
>
>
>
But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.
>
Thanks,
Vishnu


>
>


Hi,

Here is the ASPX code.

<body ms_positioning="gridlayout">
<TABLE height="471" cellSpacing="0" cellPadding="0" width="174"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="174" height="471">
<form id="form1" runat="server">
<TABLE height="157" cellSpacing="0" cellPadding="0" width="459"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD colSpan="3" height="1"></TD>
<TD colSpan="2" rowSpan="2"><asp:textbox id="txtToDate"
runat="server"></asp:textbox></TD>
</TR>
<TR vAlign="top">
<TD height="38"></TD>
<TD colSpan="2"><asp:label id="lblFDate" runat="server"
Width="87px">From Date:</asp:label></TD>
</TR>
<TR vAlign="top">
<TD colSpan="2" height="1"></TD>
<TD colSpan="3" rowSpan="2"><asp:textbox id="txtFromDate"
runat="server"></asp:textbox></TD>
</TR>
<TR vAlign="top">
<TD height="41"></TD>
<TD><asp:label id="lblTDate" runat="server" Width="83px">To
Date:</asp:label></TD>
</TR>
<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><asp:button id="btnSubmit" runat="server"
Text="Submit"></asp:button></TD>
</TR>
</TABLE>
</form>
</TD>
</TR>
</TABLE>
</body>

And am trying to call the javascript that i sent earlier in code-behind
as shown below:

btnSubmit.Attributes.Add("onClick","return
ValidateDate(document.form1.elements['" + txtFromDate.ClientID +
"'].value,document.form1.elements['"
+ txtToDate.ClientID + "'].value);");

Now the problem is that am not able to see alert msg saying that the
difference is 0 ,which takes both dates as current date and it returns
the difference as 0. Please let me know how can i solve this issue.

Thanks,
Vishnu

Milosz Skalecki wrote:

Quote:

Originally Posted by

Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD
>
>
"settyv@.gmail.com" wrote:
>

Quote:

Originally Posted by

Hi,

It is not working .it is telling script error.Here is the HTML created
after the postback.Everything is fine.But i dont know why it is telling
error.

Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
is null or not an object

<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><input type="submit" name="btnSubmit" value="Submit"
id="btnSubmit" onClick="return
ValidateDate(document.getElementById["txtFromDate"].Value,document.getElementById["txtToDate"].Value);"
/></TD>
</TR>

Please let me know how can i solve this.

Thanks,
Vishnu

rampabbaraju@.gmail.com wrote:

Quote:

Originally Posted by

Try this
>
btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");
>
>
>
settyv@.gmail.com wrote:
Hi,

Below is the Javascript function that am trying to call from asp:Button
control.

<script language="javascript">
function ValidateDate(fromDate,toDate)
{

var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}

if( diffDate 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}

return true; //allow submit
}
</script>


In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");



But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.

Thanks,
Vishnu



You're assigning both dates to current date:
fromDate = new Date();
toDate = new Date();
that's why you always get 0 in difference.

it should look like this:
-- begin javascript code --

function ValidateDate(fromDateStr,toDateStr)
{

var fromDate = new Date(fromDateStr) ;
var toDate = new Date(toDateStr);
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );

alert(fromDate.toGMTString() + "\n" + toDate.toGMTString() + "\n" +
diffDate);

if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!");
return false;
}

if( diffDate 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}

return true; //allow submit
}

-- end javascript code --

and the Page_Load in code behind:

-- begin c# code --

btnSubmit.Attributes.Add("onClick", String.Format("return
ValidateDate(document.getElementById('{0}').value,
document.getElementById('{1}').value);",
txtFromDate.ClientID , txtToDate.ClientID));
-- end c# code --

Before you start working with dates in javascript please familirize yourself
with potential problems since date strings are always ambiguous, (i.e. you
should use
new Date (year, month [, date [, hours [, minutes [, seconds [, ms ]]]]])

hope this helps

--
Milosz Skalecki
MCP, MCAD

"settyv@.gmail.com" wrote:

Quote:

Originally Posted by

Hi,
>
Here is the ASPX code.
>
<body ms_positioning="gridlayout">
<TABLE height="471" cellSpacing="0" cellPadding="0" width="174"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="174" height="471">
<form id="form1" runat="server">
<TABLE height="157" cellSpacing="0" cellPadding="0" width="459"
border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD colSpan="3" height="1"></TD>
<TD colSpan="2" rowSpan="2"><asp:textbox id="txtToDate"
runat="server"></asp:textbox></TD>
</TR>
<TR vAlign="top">
<TD height="38"></TD>
<TD colSpan="2"><asp:label id="lblFDate" runat="server"
Width="87px">From Date:</asp:label></TD>
</TR>
<TR vAlign="top">
<TD colSpan="2" height="1"></TD>
<TD colSpan="3" rowSpan="2"><asp:textbox id="txtFromDate"
runat="server"></asp:textbox></TD>
</TR>
<TR vAlign="top">
<TD height="41"></TD>
<TD><asp:label id="lblTDate" runat="server" Width="83px">To
Date:</asp:label></TD>
</TR>
<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><asp:button id="btnSubmit" runat="server"
Text="Submit"></asp:button></TD>
</TR>
</TABLE>
</form>
</TD>
</TR>
</TABLE>
</body>
>
And am trying to call the javascript that i sent earlier in code-behind
as shown below:
>
btnSubmit.Attributes.Add("onClick","return
ValidateDate(document.form1.elements['" + txtFromDate.ClientID +
"'].value,document.form1.elements['"
+ txtToDate.ClientID + "'].value);");
>
>
Now the problem is that am not able to see alert msg saying that the
difference is 0 ,which takes both dates as current date and it returns
the difference as 0. Please let me know how can i solve this issue.
>
Thanks,
Vishnu
>
>
>
Milosz Skalecki wrote:

Quote:

Originally Posted by

Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD

"settyv@.gmail.com" wrote:

Quote:

Originally Posted by

Hi,
>
It is not working .it is telling script error.Here is the HTML created
after the postback.Everything is fine.But i dont know why it is telling
error.
>
Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
is null or not an object
>
<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><input type="submit" name="btnSubmit" value="Submit"
id="btnSubmit" onClick="return
ValidateDate(document.getElementById["txtFromDate"].Value,document.getElementById["txtToDate"].Value);"
/></TD>
</TR>
>
Please let me know how can i solve this.
>
>
Thanks,
Vishnu
>
rampabbaraju@.gmail.com wrote:
Try this

btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");



settyv@.gmail.com wrote:
Hi,
>
Below is the Javascript function that am trying to call from asp:Button
control.
>
<script language="javascript">
function ValidateDate(fromDate,toDate)
{
>
var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}
>
if( diffDate 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}
>
return true; //allow submit
}
</script>
>
>
In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");
>
>
>
But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.
>
Thanks,
Vishnu
>
>


>
>