0

I have problem with array parameter in a stored procedure.

My code:

var command = "DECLARE  @return_value int EXEC  @return_value = [dbo].[GetEmployeeData]  @EmployeeId, @StartTime, @StopTime";

SqlDataAdapter tableAdapter = new SqlDataAdapter(command, cnn);

// Set SQL Server parameters
tableAdapter.SelectCommand.Parameters.Add(new SqlParameter("@StartTime", DateTime.Parse(dtpRepEmFrom.Text)));
tableAdapter.SelectCommand.Parameters.Add(new SqlParameter("@StopTime", DateTime.Parse(dtpRepEmTo.Text)));
tableAdapter.SelectCommand.Parameters.Add(new SqlParameter("@EmployeeId", keyList.ToArray()));

var dataTable = new DataTable();

// Get data
tableAdapter.Fill(dataTable);

keylist is an array of integer (and EmployeeId is int type in database).

I get an error when I fill the dataTable:

No mapping exists from object type System.Int32[] to a known managed provider native type.

Please help me how I add array into parameter.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Why don't you pass an `empoyeeId` and you pass an array? This doesn't make sence. I refer to this `keyList.ToArray()`. Does you stored procedure returns data for an employee or of a list of employees? In other words, what's the type of `@EmployeeId` parameter? I – Christos Nov 20 '16 at 10:18
  • Stored procedure return table with the manufactured products for the group of Employees (EmployeeId is int type) – JaCzProg01 Nov 20 '16 at 10:34
  • See http://stackoverflow.com/questions/11102358/how-to-pass-an-array-into-a-sql-server-stored-procedure – M. Rezaeyan Nov 20 '16 at 11:08

0 Answers0