how to call userdefined function in asp.net

Posted by Parthibansk under ASP.NET on 8/13/2012 | Points: 10 | Views : 3015 | Status : [Member] | Replies : 4
I CREATED a table with fiscal year as one column..
created userdefined function for returning fiscal year..how to call tat fiscalyear udf in asp.net..

got a webpage when we click the textbox it should automatically detect fiscal year and make it as default..




Responses

Posted by: Andrewpattinson on: 8/13/2012 [Member] Starter | Points: 25

Up
0
Down
Write the stored procedure and UDF logic as Visual Basic code in a class. Once the code has been written, we will need to compile this class into an assembly (a .dll file), register the assembly with the SQL Server database, and then create a stored procedure or UDF object in the database that points to the corresponding method in the assembly. These steps can all be performed manually
http://www.dapfor.com/en/net-suite/net-grid/tutorial/headers-and-columns


Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/13/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
can you please share your Sample code??
OR
you can use java script on textbox change event.
eg :
look at this url
http://www.dotnetfunda.com/articles/article72.aspx

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 8/13/2012 [Member] Starter | Points: 25

Up
0
Down
create FUNCTION Fiscalyear (@CurrentDATE datetime)
RETURNS int

AS
BEGIN
DECLARE @FiscalDay int;
DECLARE @YearStartDate DateTime;
Set @YearStartDate=Cast('20120401' As DateTime)
set @FiscalDay = DATEDIFF(DAY,@YearStartDate , @CurrentDATE)
RETURN(@FiscalDay);
END;


Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/13/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this
  

cmd.CommandText = "select Fiscalyear(@CurrentDATE) as functionresult";
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("CurrentDATE ", DateTime.Now);
string yourresult;
SqlDataReader dr;
// con.Open();
dr = cmd.ExecuteReader();
if(dr.Read())
yourresult = dr["functionResult"].ToString(); // dr[0].ToString();
// con.Close();


Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response