TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
basim salih
NA
84
8.9k
Help me..calling a scalar function in sql server within c#?
Dec 11 2017 2:37 PM
i have a scalar function "[finance_dep].[sum_view1]" in sql server :
ALTER
function
[finance_dep].[sum_view1] (@dt1 datetime, @dt2 datetime )
returns
decimal
as
begin
Declare
@d
decimal
set
@d=(
select
sum
([amount_dnr])
from
[finance_dep].[view1]
where
[wsl_date]
between
@dt1
and
@dt2)
return
@d
end
when i calling it from c#:
public
static
decimal
sum_v(DateTime @dt1, DateTime @dt2)
{
return
exscalarfunction(
"select cast(finance_dep.sum_view1(@dt1,@dt2) as decimal) "
, CommandType.Text,
CreateParam(
"@dt1"
, SqlDbType.DateTime, @dt1),
CreateParam(
"@dt2"
, SqlDbType.DateTime, @dt2));
}
protected
static
decimal
exscalarfunction(
string
querystoredprocedure, CommandType type,
params
SqlParameter[] param)
{
cn.Open();
//*******************
decimal
f;
cmd =
new
SqlCommand(querystoredprocedure, cn);
cmd.CommandType = type;
cmd.Parameters.AddRange(param);
//********************
f = (
decimal
) cmd.ExecuteScalar();
// here appear error with message ()
//***********************************
cn.Close();
return
f;
}
Reply
Answers (
4
)
XML parsing: line 14, character 49, whitespace expected
How to Remove HTML Tags from String in SQL Server