Answered by:
calling user defined function in c#

Question
-
User368447519 posted
hi,
i have one user defined function in sql2000, i'm going to call it via query in c# but i don't know,how !
please help me with sample code...
thanks
Wednesday, September 3, 2008 2:21 AM
Answers
-
User-22218653 posted
You cannt directly call function in C#, what you can do is.
stored procedure which call this and give you result bakc, or in commandtext write the select statement which calls the UDF
Hope this helps you.
@bhadelia:
here is a sample how to call database function
1 String ssss = ConnectionManager.Instance.GetFunctionData("test");
1 public String GetFunctionData(String showFunctionData)
2 {
3 queryString = "select dbo.fn_checkFunction('"+showFunctionData+"')";
4 commandSql = new SqlCommand(queryString, connectionSql);
5 connectionSql.Open();
6 dataReaderSql = commandSql.ExecuteReader();
7 string retu = "";
8 while (dataReaderSql.Read())
9 {
10 retu= dataReaderSql[0].ToString();
11 break;
12 }
13 dataReaderSql.Close();
14 connectionSql.Dispose();
15 connectionSql.Close();
16 return retu;
17 }1 CREATE function dbo.fn_checkFunction(@id nvarchar(4000))
2 returns nvarchar(4000)
3 as
4 begin
5 return @id
6 end
7- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 3, 2008 4:07 AM
All replies
-
User-22218653 posted
your sql will be "Select dbo.YourDataBaseFunction(@Parm1, @Parm2, @Parm3)"
here i'm using parametrized(@Param1,@....) query and most of the code r same (like selecting data's from a table)
Wednesday, September 3, 2008 3:39 AM -
User599164775 posted
You cannt directly call function in C#, what you can do is.
stored procedure which call this and give you result bakc, or in commandtext write the select statement which calls the UDF
Hope this helps you.
Wednesday, September 3, 2008 3:40 AM -
User-22218653 posted
You cannt directly call function in C#, what you can do is.
stored procedure which call this and give you result bakc, or in commandtext write the select statement which calls the UDF
Hope this helps you.
@bhadelia:
here is a sample how to call database function
1 String ssss = ConnectionManager.Instance.GetFunctionData("test");
1 public String GetFunctionData(String showFunctionData)
2 {
3 queryString = "select dbo.fn_checkFunction('"+showFunctionData+"')";
4 commandSql = new SqlCommand(queryString, connectionSql);
5 connectionSql.Open();
6 dataReaderSql = commandSql.ExecuteReader();
7 string retu = "";
8 while (dataReaderSql.Read())
9 {
10 retu= dataReaderSql[0].ToString();
11 break;
12 }
13 dataReaderSql.Close();
14 connectionSql.Dispose();
15 connectionSql.Close();
16 return retu;
17 }1 CREATE function dbo.fn_checkFunction(@id nvarchar(4000))
2 returns nvarchar(4000)
3 as
4 begin
5 return @id
6 end
7- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 3, 2008 4:07 AM -
User217778716 posted
please first give the detail of functions and its parameter like; what the function is and what are its passing & returning parameters.
Thursday, November 11, 2010 8:17 AM