I'm trying to call a stored procedure within 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 console, but the database still isn't updated.
This is the 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
Running the 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 code form C# doesn't.