I am trying to call a stored procedure in C #.
using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = connection.CreateCommand()) { command.CommandType = CommandType.StoredProcedure; command.CommandText = "updateData"; command.Parameters.Add(new SqlParameter("@inrego", rego)); command.Parameters.Add(new SqlParameter("@inOprt", oprt)); command.Parameters.Add(new SqlParameter("@inService", service)); connection.Open(); int update = command.ExecuteNonQuery(); Console.WriteLine(update); connection.Close(); }
update shows 1 on the console, but the database is still not updating.
This is a stored procedure.
CREATE PROCEDURE [dbo].updateData @inrego varchar(5), @inOprt char(3), @inService as varchar(50) AS delete from buses where rego = @inrego; insert into buses (rego, operator,service) values(@inrego, @inOprt, @inService); RETURN 0
Starting a stored procedure manually works, aka
USE [C:\USERS\---\DOCUMENTS\VISUAL STUDIO 2013\PROJECTS\---\TEST.DB.MDF] GO DECLARE @return_value Int EXEC @return_value = [dbo].[updateData] @inrego = N'1', @inOprt = N'2', @inService = N'3' SELECT @return_value as 'Return Value' GO
works and successfully updates the database, but the C # code form does not work.
source share