I’m running a program with an objectdatasource and a gridview. My Update method looks as if it’s passing through the program correctly. But when it gets to the DB, there’s some syntax error.
Here’s the stored proc
USE [starch]
GO
/****** Object: StoredProcedure [dbo].[Starch_Update_KPCodes] Script Date: 09/13/2011 11:02:1 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[Stored_proc_name]
(
@bookcode as varchar(15),
@PC as varchar(10),
@EReader as varchar(10),
@Tablet as varchar(10),
@Mobile as varchar(10)
)
AS
Begin
Update storedproc
SET
Valid_Ans_Nbr = @PC
where
kp_Column=82 and BookCode = @bookcode
Update
Valid_Answers
SET
Valid_Ans_Nbr = @EReader
where
kp_Column=83 and BookCode = @bookcode
Update
Valid_Answers
SET
Valid_Ans_Nbr = @Tablet
where
kp_Column=84 and BookCode = @bookcode
Update
alid_Answers
Set
Valid_Ans_Nbr = @Mobile
where
kp_Column=85 and BookCode = @bookcode
END
And then here’s what’s passed to the database in SQL profiler
exec sp_executesql N'Starch_Update_KPCodes',
N'@bookcode nvarchar(8),
@PC nvarchar(1),
@EReader nvarchar(1),
@Tablet nvarchar(1),
@Mobile nvarchar(1)',
@bookcode=N'A0027232',
@PC=N'1',
@EReader=N'1',
@Tablet=N'1',
@Mobile=N'1'
Part of what I think is going on is that I’ve dropped and recreated the stored procedure a few times. And this line
N'@bookcode nvarchar(8),@PC nvarchar(1),@EReader nvarchar(1),
@Tablet nvarchar(1),@Mobile nvarchar(1)'
probably pertains to some cached version of the stored proc.
I’ve checked my objectdatasource’s updating event to make sure it has the right paramaters.
How can I get rid of that extra text that is being passed to the stored procedure?
You presumably need to set the command type to stored procedure.
Your existing code will just try and execute the bare statement
Starch_Update_KPCodesand the parameters you pass in are unused anywhere in that statement.To do this via
sp_executesqlthe statement would need to beWhich would be a bit silly compared to just calling the stored proc directly!