Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 11, 2010 12:17 PM by jain1607
Member
19 Points
57 Posts
Sep 03, 2008 06:21 AM|LINK
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
Contributor
2297 Points
392 Posts
Sep 03, 2008 07:39 AM|LINK
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)
3191 Points
533 Posts
Sep 03, 2008 07:40 AM|LINK
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.
Sep 03, 2008 08:07 AM|LINK
bhadelia.imran 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
String ssss = ConnectionManager.Instance.GetFunctionData("test");
public String GetFunctionData(String showFunctionData) { queryString = "select dbo.fn_checkFunction('"+showFunctionData+"')"; commandSql = new SqlCommand(queryString, connectionSql); connectionSql.Open(); dataReaderSql = commandSql.ExecuteReader(); string retu = ""; while (dataReaderSql.Read()) { retu= dataReaderSql[0].ToString(); break; } dataReaderSql.Close(); connectionSql.Dispose(); connectionSql.Close(); return retu; } CREATE function dbo.fn_checkFunction(@id nvarchar(4000))returns nvarchar(4000)asbeginreturn @idend
public String GetFunctionData(String showFunctionData) { queryString = "select dbo.fn_checkFunction('"+showFunctionData+"')"; commandSql = new SqlCommand(queryString, connectionSql); connectionSql.Open(); dataReaderSql = commandSql.ExecuteReader(); string retu = ""; while (dataReaderSql.Read()) { retu= dataReaderSql[0].ToString(); break; } dataReaderSql.Close(); connectionSql.Dispose(); connectionSql.Close(); return retu; }
CREATE function dbo.fn_checkFunction(@id nvarchar(4000))returns nvarchar(4000)asbeginreturn @idend
2 Points
1 Post
Nov 11, 2010 12:17 PM|LINK
please first give the detail of functions and its parameter like; what the function is and what are its passing & returning parameters.
functionns
mojde
Member
19 Points
57 Posts
calling user defined function in c#
Sep 03, 2008 06:21 AM|LINK
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
kamrul3d
Contributor
2297 Points
392 Posts
Re: calling user defined function in c#
Sep 03, 2008 07:39 AM|LINK
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)
Kamrul Hassan
please mark as answer if it helps u.
bhadelia.imr...
Contributor
3191 Points
533 Posts
Re: calling user defined function in c#
Sep 03, 2008 07:40 AM|LINK
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.
[MCTS]
Born to fly High
http://knowledgebaseworld.blogspot.com/
kamrul3d
Contributor
2297 Points
392 Posts
Re: calling user defined function in c#
Sep 03, 2008 08:07 AM|LINK
@bhadelia:
here is a sample how to call database function
String ssss = ConnectionManager.Instance.GetFunctionData("test");Kamrul Hassan
please mark as answer if it helps u.
jain1607
Member
2 Points
1 Post
Re: calling user defined function in c#
Nov 11, 2010 12:17 PM|LINK
please first give the detail of functions and its parameter like; what the function is and what are its passing & returning parameters.
functionns