Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET使用LINQ调用存储过程并传入DataTable_Asp.net_Linq_Stored Procedures_Datatable - Fatal编程技术网

ASP.NET使用LINQ调用存储过程并传入DataTable

ASP.NET使用LINQ调用存储过程并传入DataTable,asp.net,linq,stored-procedures,datatable,Asp.net,Linq,Stored Procedures,Datatable,我做错了什么? 尝试使用LINQ将我的数据表传递到存储的进程。下面是我的代码 var sqlCommand = new System.Data.SqlClient.SqlCommand { CommandType = System.Data.CommandType.StoredProcedure, CommandText = "UserIdList" }; var dataTable = new System.Data.DataTable("IdList"); dataTabl

我做错了什么? 尝试使用LINQ将我的数据表传递到存储的进程。下面是我的代码

var sqlCommand = new System.Data.SqlClient.SqlCommand { CommandType = System.Data.CommandType.StoredProcedure, CommandText = "UserIdList" }; var dataTable = new System.Data.DataTable("IdList"); dataTable.Columns.Add("AttributeIds", typeof(Int32)); dataTable.Rows.Add(26); dataTable.Rows.Add(40); dataTable.Rows.Add(41); dataTable.Rows.Add(45); dataTable.Rows.Add(78); dataTable.Rows.Add(33); dataTable.Rows.Add(36); //The parameter for the SP must be of SqlDbType.Structured var parameter = new System.Data.SqlClient.SqlParameter { ParameterName = "@AttributeIds", SqlDbType = System.Data.SqlDbType.Structured, TypeName = "ecs.IDList", Value = dataTable, }; sqlCommand.Parameters.Add(parameter); var user = myDC.DC.ExecuteQuery("exec ecs.udpUserAttributeDetails {0}, {1}", sqlCommand, userId).SingleOrDefault(); var sqlCommand=new System.Data.SqlClient.sqlCommand{ CommandType=System.Data.CommandType.StoredProcess, CommandText=“UserIdList” }; var dataTable=new System.Data.dataTable(“IdList”); Add(“AttributeIds”,typeof(Int32)); dataTable.Rows.Add(26); dataTable.Rows.Add(40); dataTable.Rows.Add(41); dataTable.Rows.Add(45); dataTable.Rows.Add(78); dataTable.Rows.Add(33); dataTable.Rows.Add(36); //SP的参数必须为SqlDbType.Structured var parameter=new System.Data.SqlClient.SqlParameter{ ParameterName=“@AttributeIds”, SqlDbType=System.Data.SqlDbType.Structured, TypeName=“ecs.IDList”, 值=数据表, }; sqlCommand.Parameters.Add(参数); var user=myDC.DC.ExecuteQuery(“exec ecs.udpUserAttributeDetails{0},{1}”,sqlCommand,userId);
这似乎就是问题所在

var user = myDC.DC.ExecuteQuery("exec ecs.udpUserAttributeDetails {0}, {1}", sqlCommand, userId).SingleOrDefault();
在代码中,将sqlCommand对象作为第一个参数传递,将userId作为第二个参数传递

数据上下文

ExecuteQuery(字符串,对象[])
ExecuteQuery(类型、字符串、对象[])
您似乎在使用重载1,即
ExecuteQuery(String,Object[])
,但在这种情况下,您需要指定返回对象的类型

例如:-

var customers=db.ExecuteQuery(@“从dbo.customers WHERE City={0}”、“London”中选择CustomerID、CompanyName、ContactName);
注意:db.ExecuteQuery
在上面的示例中就是我所指的


我认为这可能是错误的原因,因为编译器正在将您的请求映射到重载2,而重载2不返回任何值,而是接受3个参数,这导致您的
查询参数不能是'System.Data.SqlClient.SqlCommand
错误。

而您得到的错误是???@InSane-error msg是:一个查询参数的类型不能为“System.Data.SqlClient.SqlCommand”。对象的数据类型是什么?
ExecuteQuery<TResult>(String, Object[]) 
ExecuteQuery(Type, String, Object[])
 var customers = db.ExecuteQuery<Customer>(@"SELECT CustomerID, CompanyName, ContactName FROM dbo.Customers WHERE  City = {0}", "London");