on the report page I add the the data so is like below
row 1 / some data / calcuation based on variable / link based on row to add data
Once the data is added in from the link on that row it is used in the calculation.
As validation you need to see the report as you add in the data.
IF all the data is inputted into the database the Page DOES loads correctly and works perfect.
I am using a call to a function to create a these numbers.
here is the error
The best overloaded method match for 'ASP.Functions.TestMatch(string, int)' has some invalid arguments
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'ASP.Functions.TestMatch(string, int)' has some invalid arguments
Source Error:
Line 88:
Line 89:
Line 90: var Fac1Total=Functions.TestMatch(Fac1Raw, FacJob1);
Line 91: var Fac2Total=Functions.TestMatchExact(Fac2Raw, FacJob2);
Line 92: var Fac3Total=Functions.TestMatch(Fac3Raw, FacJob3);
These variables cannot be calculated because Fac1Raw is currently null so is Fac2Raw and Fac3Raw.
Here is the testmatch function for reference.
public static string TestMatch(string range, int comp)
{
string result = "Not Matched";
// removes characters from the string
// (http://stackoverflow.com/questions/4366422/how-to-remove-characters-from-a-string-using-linq)
string strDigits = new String(range.Where(Char.IsDigit).ToArray());
// creates upper and lower limits
int lower = (strDigits.Length > 0 ? Convert.ToInt16(strDigits.Substring(0,1)) : 0);
int upper = (strDigits.Length > 1 ? Convert.ToInt16(strDigits.Substring(1,1)) : lower);
// compares values
if (comp >= lower && comp <= upper)
{
result = "Matched";
}
else if (comp >= (lower - 1) && comp <= (upper + 1))
{
result = "Variation";
}
return result;
}
If it cannot be calculated i would like nothing to be displayed to the user so it obvious that something is required. However i need a work around so that the page still processess.
What is this doing, i dont quite understand the code here??
Your programs throws an exception when the db value is null because it can't get a string from a null value and the function signature expects a string and an integer.
The ToString method forces the conversion of the null value into an empty string and avoids the exception.
Now your TestMatch function should manage an empty string: I have considered a new case (Not Available), but you can change your code as you prefer.
However this would be checking if 'range' is null or empty.
I think that it needs to check if range or comp are empty it should return not available?
Would i type
if (string.IsNullOrEmpty(range) || int.IsNullOrEmpty(comp)
{
result = "Not Available";
}
instead? this doesnt work and should it say int. ? if this isnt possible it should HAVE to check 'range' as this should always have an entry its more comp thats is the issues.
public static string TestMatch(string range, int comp)
{
string result = "Not Matched";
if (string.IsNullOrEmpty(range))
{
result = "Not Available";
}
else
{
// removes characters from the string
// (http://stackoverflow.com/questions/4366422/how-to-remove-characters-from-a-string-using-linq)
string strDigits = new String(range.Where(Char.IsDigit).ToArray());
// creates upper and lower limits
int lower = (strDigits.Length > 0 ? Convert.ToInt16(strDigits.Substring(0,1)) : 0);
int upper = (strDigits.Length > 1 ? Convert.ToInt16(strDigits.Substring(1,1)) : lower);
// compares values
if (comp >= lower && comp <= upper)
{
result = "Matched";
}
else if (comp >= (lower - 1) && comp <= (upper + 1))
{
result = "Variation";
}
}
return result;
}
getting close to the end of my project and would like to give a massive thanks!
Before i start i did add a addtional ')' at the end of the below as it was required i believe..
var Fac1Total=Functions.TestMatch(Fac1Raw.ToString(), (FacJob1 != DBNull.Value ? FacJob1 : -1));
So i added this code, and it is still giving the below error.
This is when i create a new entry and the variable FacJob# has no value...
Server Error in '/' Application.
The best overloaded method match for 'ASP.Functions.TestMatch(string, int)' has some invalid arguments
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'ASP.Functions.TestMatch(string, int)' has some invalid arguments
Source Error:
Line 86:
Line 87:
Line 88: var Fac1Total=Functions.TestMatch(Fac1Raw.ToString(), (FacJob1 != DBNull.Value ? FacJob1 : -1));
Line 89: var Fac2Total=Functions.TestMatch(Fac2Raw.ToString(), (FacJob2 != DBNull.Value ? FacJob2 : -1));
Line 90: var Fac3Total=Functions.TestMatch(Fac3Raw.ToString(), (FacJob3 != DBNull.Value ? FacJob3 : -1));
If i test it when it does have a value it now also gives an error (which it didnt before)
See below.
Server Error in '/' Application.
Operator '!=' cannot be applied to operands of type 'int' and 'System.DBNull'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator '!=' cannot be applied to operands of type 'int' and 'System.DBNull'
Source Error:
Line 86:
Line 87:
Line 88: var Fac1Total=Functions.TestMatch(Fac1Raw.ToString(), (FacJob1 != DBNull.Value ? FacJob1 : -1));
Line 89: var Fac2Total=Functions.TestMatch(Fac2Raw.ToString(), (FacJob2 != DBNull.Value ? FacJob2 : -1));
Line 90: var Fac3Total=Functions.TestMatch(Fac3Raw.ToString(), (FacJob3 != DBNull.Value ? FacJob3 : -1));
happysack
Member
18 Points
46 Posts
'dont do calulations' IF 'no data no in db yet'
Nov 20, 2012 09:56 PM|LINK
So....
I have a ' report page '
on the report page I add the the data so is like below
row 1 / some data / calcuation based on variable / link based on row to add data
Once the data is added in from the link on that row it is used in the calculation.
As validation you need to see the report as you add in the data.
IF all the data is inputted into the database the Page DOES loads correctly and works perfect.
I am using a call to a function to create a these numbers.
here is the error
These variables cannot be calculated because Fac1Raw is currently null so is Fac2Raw and Fac3Raw.
Here is the testmatch function for reference.
public static string TestMatch(string range, int comp) { string result = "Not Matched"; // removes characters from the string // (http://stackoverflow.com/questions/4366422/how-to-remove-characters-from-a-string-using-linq) string strDigits = new String(range.Where(Char.IsDigit).ToArray()); // creates upper and lower limits int lower = (strDigits.Length > 0 ? Convert.ToInt16(strDigits.Substring(0,1)) : 0); int upper = (strDigits.Length > 1 ? Convert.ToInt16(strDigits.Substring(1,1)) : lower); // compares values if (comp >= lower && comp <= upper) { result = "Matched"; } else if (comp >= (lower - 1) && comp <= (upper + 1)) { result = "Variation"; } return result; }If it cannot be calculated i would like nothing to be displayed to the user so it obvious that something is required. However i need a work around so that the page still processess.
I hope this make sense.
Many thanks
GmGregori
Contributor
5438 Points
730 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 20, 2012 11:00 PM|LINK
I'm not sure that this could be the solution for your problem but, anyway, it works.
Modify your TestMatch function like in the following:
public static string TestMatch(string range, int comp) { string result = "Not Matched"; if (string.IsNullOrEmpty(range)) { result = "Not Available"; } else { // removes characters from the string // (http://stackoverflow.com/questions/4366422/how-to-remove-characters-from-a-string-using-linq) string strDigits = new String(range.Where(Char.IsDigit).ToArray()); // creates upper and lower limits int lower = (strDigits.Length > 0 ? Convert.ToInt16(strDigits.Substring(0,1)) : 0); int upper = (strDigits.Length > 1 ? Convert.ToInt16(strDigits.Substring(1,1)) : lower); // compares values if (comp >= lower && comp <= upper) { result = "Matched"; } else if (comp >= (lower - 1) && comp <= (upper + 1)) { result = "Variation"; } } return result; }and force your variable convertion before to pass it to the function
ayanmesut
Member
219 Points
85 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 21, 2012 07:38 AM|LINK
you check the value of the Fac1Raw and the others ad be sure that they are not null.
if (Fac1Raw != null && FacJob1 != null){ var Fac1Total=Functions.TestMatch(Fac1Raw, FacJob1); }happysack
Member
18 Points
46 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 21, 2012 01:26 PM|LINK
What is this doing, i dont quite understand the code here??
As i am calling Fac1Total in the body could i amend it to ..
if (Fac1Raw != null && FacJob1 != null){ var Fac1Total=Functions.TestMatch(Fac1Raw, FacJob1); } else {var Fac1Total="";}would that work? it doesn't but should it?
happysack
Member
18 Points
46 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 21, 2012 01:29 PM|LINK
..
GmGregori
Contributor
5438 Points
730 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 21, 2012 03:44 PM|LINK
Your programs throws an exception when the db value is null because it can't get a string from a null value and the function signature expects a string and an integer.
The ToString method forces the conversion of the null value into an empty string and avoids the exception.
Now your TestMatch function should manage an empty string: I have considered a new case (Not Available), but you can change your code as you prefer.
happysack
Member
18 Points
46 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 21, 2012 06:38 PM|LINK
I think that this code is right..
below
However this would be checking if 'range' is null or empty.
I think that it needs to check if range or comp are empty it should return not available?
Would i type
if (string.IsNullOrEmpty(range) || int.IsNullOrEmpty(comp) { result = "Not Available"; }instead? this doesnt work and should it say int. ? if this isnt possible it should HAVE to check 'range' as this should always have an entry its more comp thats is the issues.
public static string TestMatch(string range, int comp) { string result = "Not Matched"; if (string.IsNullOrEmpty(range)) { result = "Not Available"; } else { // removes characters from the string // (http://stackoverflow.com/questions/4366422/how-to-remove-characters-from-a-string-using-linq) string strDigits = new String(range.Where(Char.IsDigit).ToArray()); // creates upper and lower limits int lower = (strDigits.Length > 0 ? Convert.ToInt16(strDigits.Substring(0,1)) : 0); int upper = (strDigits.Length > 1 ? Convert.ToInt16(strDigits.Substring(1,1)) : lower); // compares values if (comp >= lower && comp <= upper) { result = "Matched"; } else if (comp >= (lower - 1) && comp <= (upper + 1)) { result = "Variation"; } } return result; }getting close to the end of my project and would like to give a massive thanks!
happysack
Member
18 Points
46 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 21, 2012 07:50 PM|LINK
i think the problem is that comp is an int
and i then need to check that for a null, from what i have read you cannot check for null on a int.
Could we do this check before changing it to an int?
Not sure how to do it, but think this would resolve.
It needs to be int after this check however because it needs to be calculated on?
Many many thanks in advance again
thank you :)
GmGregori
Contributor
5438 Points
730 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 21, 2012 08:40 PM|LINK
Try
and modify your TestMatch function:
... if (string.IsNullOrEmpty(range) || comp < 0) { result = "Not Available"; } else { ...happysack
Member
18 Points
46 Posts
Re: 'dont do calulations' IF 'no data no in db yet'
Nov 22, 2012 08:25 AM|LINK
If i test it when it does have a value it now also gives an error (which it didnt before)
See below.