How do I Execute Stored Procedures and Views?

This article explains that how we can execute stored procedures and views.You can execute stored procedures and views using three execute methods of SqlCommand object.
  • 1127

You can execute stored procedures and views using three execute methods (ExecuteNonQuery, ExecuteReader, and ExecuteScalar) methods of SqlCommand object. Before you call execute method of SqlCommand to execute a stored procedure, you need to set SqlCommand.CommandType property to CommandType.StoredProcedure and SqlCommand.CommandText as stored procedure name.

Private cmd As SqlCommand = New SqlCommand()
Private cmd.Connection = con
Private cmd.CommandType = CommandType.StoredProcedure
Private cmd.CommandText = "CustOrderHist"

You can also use stored procedure and views in your SELECT statements to retrieve data from stored procedures and views. Instead of a database table name, you use stored procedure or view name.

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.