How to call database function in ?

There are 3 type functions in Sqlserver 2008. These are
1.Scalar function
2.Inline scalar Function
3.Table valued Function

Scalar Function: It is used to return the single value from database.
Inline Scalar Function:It is similar to scalar function but it doesn’t contain function body.It’s means doesn’t contain Begin/End block.
Table-Valued Function:It is used to return the table data type.

Here i m going to show to how to call simple scalar function in

Step1:Create the Scalar function in database like this

CREATE FUNCTION [dbo].[Multiply](@A int,@B int)

Return @A*@B

Step2: Create one simple page and write the code on click event like this

protected void Button1_Click(object sender, EventArgs e)
int a1 = Convert.ToInt32(TextBox1.Text);
int b1 = Convert.ToInt32(TextBox2.Text);
SqlConnection con = new SqlConnection("Data Source=.\\sqlExpress;Initial Catalog=Test;Integrated Security=True");
SqlCommand cmd = new SqlCommand("Select dbo.Multiply(@a,@b)", con);
cmd.Parameters.AddWithValue("@a", a1);
cmd.Parameters.AddWithValue("@b", b1);
Label1.Text = Convert.ToString(cmd.ExecuteScalar());


One thought on “How to call database function in ?

  1. HEMANT UPADHYAY January 13, 2012 / 5:46 am

    can u send me code of pc based sms sending application without usin gateway Thnx in advance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.