c# - ExecuteScalar retuns NULL value -
stored procedure:
dbo.getldate select dateentered table1 id = 4, gid=5
result:
executed
new query verify:
declare @ldate datetime exec @ldate = getldate 4,5
results:
dateentered 2014-02-13 06:21:43.600
thus, working fine
final stored procedure created:
exec @ldate = getldate 4,5 select 1
in c#
int? id = _database.executescalar() int?;
here, every time null value only. selecting 1 still null value. reason this.
you selecting string '1'
, can't converted int?
cast
. hence getting null.
use:
select 1 --without single quotes
or can use convert.toint32
like:
int? id = convert.toint32(_database.executescalar());
consider following example:
object obj = "1"; int? id = obj int?;
you null
cast "1"
(string) int/int?
fail.
Comments
Post a Comment