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.
LVL 4
Brant SnowAsked:
Who is Participating?
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.
0
Kamal KhaleefaInformation Security SpecialistCommented:
hi

here is a sample

 Try

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

                oSQLConnection1.Open()

                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"

   cmd.ExecuteNonQuery()

   Catch ex As Exception
                Return False
            Finally
                Try
                    oSQLConnection1.Close()
                Catch ex As Exception

                End Try
            End Try

        Catch ex As Exception

        End Try

Open in new window

0

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=*****; "
       
       
     


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




    End Function

Open in new window

0
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
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.