how to use Store Procedure in VC# 2005 ?
C#
2
Posts
2
Posters
0
Views
1
Watching
-
hi i want to use Store Procedure for Insert,Update and Delete data in sql2005 and VC# 2005,but how to do? please give an example or article or source for me. thanks
When you create your SqlCommands, set the CommandType to CommandType.StoredProcedure. Also add the parameters needed by the stored procedure. E.g. something like this:
using (SqlConnection mySqlConnection = getConnection())
{
SqlCommand insertCommand = new SqlCommand("[dbo].[MY_INSERT_PROCEDURE]");
insertCommand.CommandType = CommandType.StoredProcedure;
insertCommand.Parameters.Add("@StringField", SqlDbType.VarChar);
insertCommand.Parameters["@StringField"].Value = "Nice new string";
insertCommand.Connection = mySqlConnection;
insertCommand.ExecuteNonQuery();
}