hi, string is a reference type, so it can hold null value also.
ie. no need to declare it as nullable,already it's capabel of holding null value, so change like below
public bool AddEmployee(string lastName, string firstName, string middleName, DateTime birthDate,
string mobileNumber, string homePhoneNumber, string city, string province, string gender)
{
return true;
}
to pass null value as paramter just use null
Thanks,
Karthick S
Marked as answer by jrtibayan on May 22, 2012 01:07 AM
string is reference type, hence they are nullable. you can just pass null in your mobileNumber parameter, there is no need to pass it with nullable type (?).
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
i see.. thats seems weird. i get an error when passing the value of the textboxes
error says
StrongTypingExeption was unhandled by user code
The value for column 'MiddleName' in table 'Employees' is DBNull.
oh btw the error is on the generated code of my typed dataset on my employeesRow
public string MiddleName {
get {
try {
return ((string)(this[this.tableEmployees.MiddleNameColumn]));
}
catch (global::System.InvalidCastException e) {
throw new global::System.Data.StrongTypingException("The value for column \'MiddleName\' in table \'Employees\' is DBNull.", e);
}
}
set {
this[this.tableEmployees.MiddleNameColumn] = value;
}
}
the code is autogenerated so i dont know what the problem is since im still learning about asp.net and i jumped to making 3tier project
jrtibayan
Member
198 Points
198 Posts
how do you pass a nullable content to a string parameter?
May 03, 2012 08:00 AM|LINK
i made a class containing my methods and this is one of the methods
public bool AddEmployee(string lastName, string firstName, string? middleName, DateTime birthDate,
string? mobileNumber, string? homePhoneNumber, string? city, string? province, string gender)
{
}
it gives an error saying "The type string must be a non-nullable value type in order to use as parameter"
does that mean i cant use string? to accept null value
im thinking i can just put a RequiredFieldValidator but i want to have the user the option to put in a particular data or not
how do you pass to a string parameter wherein the data may have a value sometimes also null
karthicks
All-Star
31376 Points
5421 Posts
Re: how do you pass a nullable content to a string parameter?
May 03, 2012 08:36 AM|LINK
hi, string is a reference type, so it can hold null value also.
ie. no need to declare it as nullable,already it's capabel of holding null value, so change like below
public bool AddEmployee(string lastName, string firstName, string middleName, DateTime birthDate, string mobileNumber, string homePhoneNumber, string city, string province, string gender) { return true; } to pass null value as paramter just use nullKarthick S
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: how do you pass a nullable content to a string parameter?
May 03, 2012 08:39 AM|LINK
string is reference type, hence they are nullable. you can just pass null in your mobileNumber parameter, there is no need to pass it with nullable type (?).
Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
jrtibayan
Member
198 Points
198 Posts
Re: how do you pass a nullable content to a string parameter?
May 03, 2012 10:01 AM|LINK
i see.. thats seems weird. i get an error when passing the value of the textboxes
error says
StrongTypingExeption was unhandled by user code
The value for column 'MiddleName' in table 'Employees' is DBNull.
oh btw the error is on the generated code of my typed dataset on my employeesRow
public string MiddleName {
get {
try {
return ((string)(this[this.tableEmployees.MiddleNameColumn]));
}
catch (global::System.InvalidCastException e) {
throw new global::System.Data.StrongTypingException("The value for column \'MiddleName\' in table \'Employees\' is DBNull.", e);
}
}
set {
this[this.tableEmployees.MiddleNameColumn] = value;
}
}
the code is autogenerated so i dont know what the problem is since im still learning about asp.net and i jumped to making 3tier project
jamshed alam
Member
319 Points
105 Posts
Re: how do you pass a nullable content to a string parameter?
May 03, 2012 10:08 AM|LINK
Hi
Debug your code, and check it's seems your are passing null value to the table field which is not accepeting null value, so make that field nullable
jrtibayan
Member
198 Points
198 Posts
Re: how do you pass a nullable content to a string parameter?
May 03, 2012 10:43 AM|LINK
its a string so they say it does accept null values
plus i check my typed dataset and checked the property of those files and its AllowDBNull is set to TRUE
tho i did find a property i think i should try changing
the tutorial am following didnt mention changing the NullValue Property it is set to (Throw exception)
hope it works
jrtibayan
Member
198 Points
198 Posts
Re: how do you pass a nullable content to a string parameter?
May 03, 2012 10:55 AM|LINK
found the fix
seems the problem was not really about passing the parameter
its after the parameter was passed and used on the if condition
if (employee.IsMiddleNameNull()) employee.SetMiddleNameNull();
thank you guys for trying to help