I am trying to pass bulk values to my stored procedure using a data table as follows:
var idlist = new DataTable();
idlist.Columns.Add("sid", typeof(int));
idlist.Columns.Add("suid", typeof(int));
idlist.Rows.Add(new object[] {1, 1});
idlist.Rows.Add(new object[] {1, 2});
cmd.Parameters.Add(new SqlParameter("@SID", Convert.ToString(idlist)));
In SQL Server the stored procedure looks like this:
ALTER PROCEDURE [dbo].[SUBNETTEMP]
(
@SID as IDLISTS READONLY
)
AS
BEGIN
Create table [tempIDTable] (sid int, suid int)
Insert into [tempIDTable]
select * from @SID
END
IDLISTS is defined as table type as follows:
CREATE TYPE IDLISTS AS TABLE (
SID int, SUID int )
go
After running the program I am not sure why my stored procedure does not create temIDTable. I am not sure whether the stored procedure executed successfully or not? Can anyone pls help.
Thanks.
In your C# code, you must specify the sqlDBType to use a table-value parameter.
So try this:
See this MSDN page for more info and examples.