c# parameterized stored procedures

I have alot of sql in some of my code that i want to switch out to parameterized stored procedures.

I see lots of tutorials out there, just wondering if you have any best practice approachs to recommend, or if there is anything within the entity framework or some microsoft class that would make sense and help.

For example, if you look at this URL  https://msdn.microsoft.com/en-us/library/vstudio/zxsa8hkf(v=vs.100).aspx
Its a tutorial for a stored procedure through managed code

Why would you do this vs just writing it directly to the database?

Anyway best advice or approaches would be appreciated.
Brant SnowAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
You wouldn't generally write a CLR stored procedure unless you specifically needed to. CLR stored procedures allow you to leverage .Net code to do advanced processing that would be difficult, or resource intensive, to do with pure T-SQL.

An assembly will be deployed to the SQL server and registered with a proxy stored procedure that calls in to a method in the assembly.

The link you pointed to is referring to creating and testing a CLR enabled procedure for SQL server, rather than a pure t-sql procedure. I think the fact that it is using an overly simplified example probably doesn't help.
Kamal KhaleefaInformation Security SpecialistCommented:

here is a sample


            Dim oSQLConnection1 As System.Data.SqlClient.SqlConnection = (New DBConnection).StartConnection


                Dim cmd As New SqlClient.SqlCommand("Update_Case_Study", oSQLConnection1)
                cmd.CommandType = CommandType.StoredProcedure

                cmd.Parameters.Add(New SqlClient.SqlParameter("@Case_ID", SqlDbType.Int, 0, ParameterDirection.Input)).Value = 1
  cmd.Parameters.Add(New SqlClient.SqlParameter("@First_Name", SqlDbType.NVarChar, 30, ParameterDirection.Input)).Value ="First_Name"


   Catch ex As Exception
                Return False
                Catch ex As Exception

                End Try
            End Try

        Catch ex As Exception

        End Try

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kamal KhaleefaInformation Security SpecialistCommented:
and here is the connection to db

Public Function StartConnection() As SqlConnection

        Dim con As SqlClient.SqlConnection = Nothing

        '   Dim ConnectionString As String = "Data Source=server;Initial Catalog=dbname;Persist Security Info=True;User ID=sa;Password=*****; "

            con = New SqlClient.SqlConnection(ConnectionString)
        Catch ex As Exception
        End Try
        Return con

    End Function

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.