You can use the parameter Table Valued, and in SQL you can use cursoreither loopthe given table and look for each column in the SQL table. Here is a simple example.
Create a new database Tpye
CREATE TYPE [dbo].[SearchInDB] AS TABLE(
[Id] [int] NOT NULL
)
And in SP you pass this type from C # code. Your SP will get it like this
ALTER PROCEDURE [dbo].[YourSPNameHere]
@DataToSearch dbo.SearchInDB ReadOnly
AS
BEGIN
END
And in your code you will create DataTableand populate a datatable with values and pass them to SP like this
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
//Add rows in datatable with values
DataRow dr = dt.NewRow();
dr["Id"] = 10;
dt.Rows.Add(dr);
//Now pass this table to SP as parameter
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@DataToSearch";
parameter.SqlDbType = System.Data.SqlDbType.Structured;
parameter.Value = dt;
Note
I added only one column if you need to add another column. To get the values from the parameter passed to SP, you have to use a loop or use the cursor. Here is a link for another example
source
share