title: Operand type clash: table type is incompatible with int
body: <p>I am trying to pass a collection of integer values to stored procedure through table </p>
  
  <p>Please find below the C# code</p>
  
  <pre><code> int i = lbActors.Items.Count;
              int[] actors = new int[i];
              int j = 0;
  
              foreach (ListItem item in lbActors.Items)
              {
                  if (item.Selected == true)
                  {
                      actors[j] = Convert.ToInt32(item.Value);
                      j++;
                  }
              }
  
              DataTable dt = new DataTable("movieAndActorType");
              dt.Columns.Add("actorId",typeof(Int32));
              int k=0;
              while(actors[k]!=0)
              {
                  dt.Rows.Add(actors[k]);
                  k++;
              }
              try
              {
                  sc.CommandText = "usp_AddMovie";
                  sc.Connection = sqlCon;
                  sc.CommandType = CommandType.StoredProcedure;
                  sc.Parameters.Add("@producerId", SqlDbType.Int).Value = Convert.ToInt32(ddlProducer.SelectedValue);
                 sc.Parameters.Add("@actorIds", SqlDbType.Structured).Value = dt;
                  sc.Parameters.Add("@movieName", SqlDbType.VarChar).Value = txtName.Text;
                  sc.Parameters.Add("@yearOfRelease", SqlDbType.Int).Value = Convert.ToInt32(txtReleaseYear.Text);
                  sc.Parameters.Add("@plot", SqlDbType.VarChar).Value = txtPlot.Text;
                  sc.Parameters.Add("@image", SqlDbType.Image).Value = imgbyte;
                  sqlCon.Open();
                  sc.ExecuteNonQuery();
                  sqlCon.Close();
              }
              catch(SqlException ex)
              {
                  Console.WriteLine(" SQL error" + ex.ToString());
              }
  </code></pre>
  
  <p>In the "sql server" i am trying to enter data into below two table </p>
  
  <pre><code>create table tbl_movie
  (
  movieId int primary key IDENTITY(1,1),
  producerId int foreign key references tbl_producer(producerId),
  movieName varchar(30) not null unique,
  yearOfRelease int not null check(yearOfRelease&gt;1900 and yearOfRelease&lt;=datepart(yyyy,getDate())),
  plot varchar(5000) not null,
  poster image 
  );
  
  
     create table tbl_movieAndActor                 (
  movieId int foreign key references tbl_movie(movieId),
  actorId int foreign key references tbl_actor(actorId),
  constraint pk_movieAndActor primary key (movieId,actorId)
  );
  </code></pre>
  
  <p>created user defined type to pass the data from application to the procedure</p>
  
  <pre><code>     create type movieAndActorType As Table
   (
    actorId int not null
   )
  </code></pre>
  
  <p>and the stored procedure</p>
  
  <pre><code>create proc proc_AddMovie(@producerId int,@actorIds As movieAndActorType Readonly,@movieName varchar(50),@yearOfRelease int,@plot varchar(500),@image image)
   as
   begin
  
   insert into tbl_movie(producerId,movieName,yearOfRelease,plot,poster) values(@producerId,@movieName,@yearOfRelease,@plot,@image)
  
   insert into tbl_movieAndActor(movieId,actorId) select scope_identity(),actorId from @actorIds
  
   end
  </code></pre>
  
  <p>I tested the stored procedure in sql server it works fine there but when i am passing the values through my application it is throwing sql exception.</p>
  
  <pre><code>     "Operand type clash: table type is incompatible with int"
  </code></pre>
  
  <p>I am a naive in coding, please help me to fix this issue.</p>
  
  <p>Thank you  </p>