*/
If you have a PH account, you can customize your PH profile.

Other Views

corner
*/

ADONET FAQ - Calling a Stored Procedure from An Application

How do I call a stored procedure from my application using ADO.Net?

Using stored procedures with ADO.Net in C# is extremely simple, especially when we have developed the application with SQL commands. All we need is:
  • Create a command object (SqlCommand, etc) and specify the stored procedure name
  • Set the CommandType property of the command object to the CommandType.StoredProcedure enumeration value. This tells the runtime that the command used here is a stored procedure.
That’s it! The sample code to use with data adapter is:

C# Version
	// Preparing Insert SQL Command
	SqlCommand insertCommand = new SqlCommand("InsertProc", conn);
	insertCommand.CommandType = CommandType.StoredProcedure;
	dataAdapter.InsertCommand = insertCommand;
	insertCommand.UpdatedRowSource = UpdateRowSource.None;
	...
VB.Net Version
        ' Preparing Insert SQL Command
        Dim insertCommand = New SqlCommand("InsertProc", conn)
        insertCommand.CommandType = CommandType.StoredProcedure
        dataAdapter.InsertCommand = insertCommand
        insertCommand.UpdatedRowSource = UpdateRowSource.None


Back
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.