在存储过程中传递表值参数时,对象类型system.collections.generic.list中存在无映射的解决方案 [英] Solution for no mapping exists from object type system.collections.generic.list while passing table valued parameter in store procedure

查看:91
本文介绍了在存储过程中传递表值参数时,对象类型system.collections.generic.list中存在无映射的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是两个类文件

These are two class files

public class Salary
{
    .
    .
    .
    public List<TripAllowanceDT> tripAllowancedt { get; set; }

}


public class TripAllowanceDT
{
    public int id { get; set; }
    public string BookingNumber { get; set; }
    public int NewBookingId { get; set; }
    public string TripAllowance { get; set; }
    public DateTime MultidayFromDate { get; set; }
    public int EmployeeId { get; set; }
}





这是调用存储过程的代码





This is the code for calling a stored procedure

  SqlConnection conn = new SqlConnection();
              conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBConnect"].ConnectionString;
              conn.Open();
              SqlCommand sc = new SqlCommand("SP", conn);

sc.Parameters.AddWithValue("AllowanceDT", EmployeeSalary.tripAllowancedt);
             DataTable dt = new DataTable();
              SqlDataAdapter da = new SqlDataAdapter(sc);
              sc.CommandType = CommandType.StoredProcedure;
              da.Fill(dt);





我的尝试:



我已经尝试过另一种方法,它正在那里工作,我已经调试了代码并检查了数据类型中的值。这一切都很好。

我还从存储过程中删除了表值参数的代码。

我刚刚宣布ie



What I have tried:

I have tried for another method and it is working there, I have debugged the code and check values in it with data type as well. And it's all fine.
I have also removed code for the table-valued parameter from the stored procedure.
I have just declared i.e

@AllowanceDT TableType_UpdateAllowance ReadOnly

推荐答案

您正在尝试将集合作为参数传递;没有这样的支持。

You're trying to pass a "collection" as a parameter; there is no such support.
sc.Parameters.AddWithValue("AllowanceDT", EmployeeSalary.tripAllowancedt);



SqlDbType Enum(System.Data)| Microsoft Docs [ ^ ]


这篇关于在存储过程中传递表值参数时,对象类型system.collections.generic.list中存在无映射的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆