1

In C#, I use Dapper to interact with SQL Server. I call a stored procedure that accepts 2 user-defined tables as parameters.

And I am passing a DataTable to my stored procedure. According to this page, the syntax to pass a DataTable is like this:

DataTable value = new DataTable();

DynamicParameters allParameters = new DynamicParameters();
allParameters.Add("name", value, value.AsTableValuedParameter("dbo.udt_MyTable"), ParameterDirection.Input, -1);

But I am getting this error:

Argument 3: cannot convert from 'Dapper.SqlMapper.ICustomQueryParameter' to 'System.Data.DbType?'

What is wrong with my syntax? Is the above functionality not working in Dapper?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
thecodeexplorer
  • 363
  • 1
  • 6
  • 18

1 Answers1

0
using (SqlConnection con1 = new SqlConnection(connectionstring))
 {
  using (SqlCommand cmd1 = new SqlCommand("your_procedure_name"))
    {
        cmd1.CommandType = CommandType.StoredProcedure;
        cmd1.Connection = con1;                                               

    SqlParameter Param = cmd1.Parameters.AddWithValue("@parameter_name", dt);
    Param.SqlDbType = SqlDbType.Structured;
        con1.Open();
        cmd1.ExecuteNonQuery();
        con1.Close();
    }
}
UsmanMirza
  • 278
  • 1
  • 8