Meghana M

Meghana M

  • 1.6k
  • 175
  • 23.6k

how to pass parameter used in userdefined datatype table in database

Mar 14 2023 10:23 PM

I have created user defined data type and passing parameter ,how to pass that parameter in code using C# ,i'm facing issue while passing it is getting conversion failed from list to enumerable

eg:database server

ALTER procedure [dbo].[SpUpdateID] 
    @List AS dbo.STATUSID READONLY
AS
BEGIN
 SET NOCOUNT ON;
 Select ID from @List 
END

CREATE TYPE [dbo].[STATUSID] AS TABLE(
    [ID] [int] NULL
)
GO

code :

List<object> idValues = new List<object>();

string filename = exportPath + "Data_" + datetime + ".csv";
SqlCommand cmd = new SqlCommand("SpUpdateID", connect);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter valparam = new SqlParameter("@List", idValues); 
valparam.SqlDbType = SqlDbType.Structured;
valparam.TypeName = "dbo.STATUSID";
cmd.ExecuteNonQuery();

 


Answers (1)