I created a function in SQL, now I need to use this function in my C # application.
I tried using something like this, but it seems like I'm doing it wrong, as I get:
Must declare the scalar value '@2064734117'
... when I give 2064734117 as the first parameter and 1 as the second parameter. Here is the code I'm talking about:
SqlConnection con = new SqlConnection(clsDb.connectionString); string query = string.Format("select Function1(@{0},@{1}) ", int.Parse(e.CurrentRow.Cells["CodeMeli"].Value.ToString()),1); con.Open(); SqlCommand cmd = new SqlCommand(query,con); SqlDataAdapter READER = new SqlDataAdapter(); READER.SelectCommand = cmd; DataTable table = new DataTable(); READER.Fill(table); radGridView1.DataSource = table; con.Close();
And my function takes two integer parameters and returns a table. I tested it in Visual Studio and it worked, but I could not get it to work in my application.
And this is the declaration of my function:
ALTER FUNCTION dbo.Function1 ( @ID int, @clsTypeID int ) RETURNS TABLE AS RETURN SELECT * FROM tblCLASS2 WHERE STNID = @ID AND CLASSTYPEID = @clsTypeID
Breeze
source share