CLR stored procedure with parameters

Source: Internet
Author: User

Yesterday we learned how to create and http://www.cnblogs.com/insus/p/4371762.html the CLR stored procedure simply by creating and deployment to SQL.

The following example is the implementation of CLR stored procedures with parameters:


To copy code:

SqlConnection Connection=New SqlConnection ("Context connection=true "); Connection.Open(); SqlCommand Command=new SqlCommand (); Command. Connection=connection; String sql="SELECT [FRUIT_NBR],[FRUITKIND_NBR],[Fruitname]  from [dbo].[Fruit] WHERE [Fruitname]  like @FruitName"; Command.commandtext=SQL; SqlParameter param=New SqlParameter ("@FruitName", SqlDbType.NVarChar); Param. Value=name; Command. Parameters.ADD(param); try {SqlDataReader Reader=command.            ExecuteReader (); SqlContext.Pipe.        Send (reader); } catch (Exception ex) {throw new Exception (ex).        Message); } connection.Close();
View Code


Writing CLR stored procedures is a bit like writing SQL statements directly in a program, but there are fine specifications and details that are different.

Insus.net feels that CLR stored procedures are a good fit for some of the more stable and mature procedures, when the deployment is generally not necessary to modify. Because the CLR store has an update or upgrade, you need to delete the old stored procedures and assembly that have already been stored, before you can reconfigure the new version of the CLR stored procedures.


To delete FRUITCLR assembly related stored procedures:



Then delete the assembly:


After all the drop, refer to yesterday's CLR stored procedure SQL deployment method, re-deployment ...

The following shows the execution of the newly added CLR stored procedure:

CLR stored procedure with parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.