sql server - How can I deal with the return of a null value parameter from a stored procedure to C# code? -
i have application gets grade name , pass parameter stored procedure. works except case there no grade name in grade table. need modify parameters make them accept null and/or need modify place assign parameters c# parameters can make accept value or null?
i have stored procedure. it's been shortened question:
create procedure sp_mark_test @gradename nvarchar(10) output, @gradepass bit output begin -- example only, real code not hard code in 99 select top 1 @gradename = grade.name, @gradepass = grade.pass admintest testid = 99 end
here c# code:
var sql = @"dbo.sp_mark_test @gradename out, @gradepass out"; sqlparameter[] parameters = new sqlparameter[] { new sqlparameter("@gradename", sqldbtype.nvarchar) { direction = parameterdirection.output,size = 10 }, new sqlparameter("@gradepass", sqldbtype.bit) { direction = parameterdirection.output } }; await db.database.executesqlcommandasync(sql, parameters); var gradename = (string)parameters[1].value; var gradepass = (boolean)parameters[2].value;
as requested, , quick answer, use of dbnull
such as
cmd.parameters.addwithvalue("@closedate", dbnull.value);
or use comparisons.
msdn page on dbnull class. code snippet below:
if (! dbnull.value.equals(row[fieldname])) return (string) row[fieldname] + " "; else return string.empty;
Comments
Post a Comment