Learn when you want, where you want with convenient online training courses. Sign up now!
Experts Exchange Solution brought to you by
"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.
'Assuming you have "Imports System.data.SqlClient" at the top of the file:'
'Change "String" to match the actual type of your parameters'
Sub ExecSP(ByVal Var1 As String, ByVal Var2 As String)
Dim conn As New SqlConnection("your connection string here")
Dim cmd As New SqlCommand("StoredProcedureName", conn)
cmd.CommandType = CommandType.StoredProcedure
'Change "SqlDbType.VarChar" and "10" to match the type and size of your parameter.'
'Omit the third argument for data types with a standard size (like datetime)'
cmd.Parameters.Add("@Param1Name", SqlDbType.VarChar, 10).Value = Var1
cmd.Parameters.Add("@Param2Name", SqlDbType.VarChar, 10).Value = Var2
'assumes you are not exepecting any results'
'if you are expecting results, using something like .ExecuteReader() or .ExecuteScalar() instead.'
'Handle errors here like normal'
Open in new window
Your question, your audience. Choose who sees your identity—and your question—with question security.
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.