DataReader的不返回任何结果VS尚未存储过程返回多个结果集在SQL服务器 [英] Datareader returns no results in VS yet Stored Procedure returns multiple result sets in Sql Server

查看:103
本文介绍了DataReader的不返回任何结果VS尚未存储过程返回多个结果集在SQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从我的DataReader麻烦检索结果在Visual Studio 2008年我在同一个数据库中的几个存储的特效。我能够检索那些不接收输入的参数值。然而,当我使用executreReader()方法,在存储过程的输入参数,我得到一个空的DataReader。当检查结果收集的信息出现的IEnumerable返回任何结果。我百思不得其解,因为我可以在SQL Server和返回结果集执行存储的特效。我是previously能够检索从Visual Studio中这些存储过程的行,但显然这只是停止工作一天。

I am having trouble retrieving results from my datareader in visual studio 2008. I have several stored Procs in the same database. I am able to retrieve values from those that dont receive input parameters. However, when i use the executreReader() method on a stored proc with input parameters i get an empty datareader. Upon examining the result collection the message "IEnumerable returned no results" appears. I am baffled as I can execute the stored procs within sql server and return result sets. I was previously able to retrieve rows from these stored procedures within Visual Studio but apparently it just stopped working one day.

我已经使用DataAdapter来填充我的结果数据集,并使用ExecuteReader()方法来获得一个SqlDataReader和我还是没有结果尝试。没有异常抛出无论是。我的参数都被命名为正常,但我应该能够调用这些存储的特效不带参数并有返回一个未经过滤的结果集。目前使用的code IM如下:

I have tried using a dataadapter to fill a dataset with my results and using the executereader() method to get a sqldatareader and Still I get no results. No exceptions are thrown either. My parameters are all named properly but I should be able to call these stored procs with no parameters and have that return an unfiltered result set. The code im currently using is the following:

string connStr = ConfigurationManager.ConnectionStrings["MyConnectionString"]
                                     .ConnectionString;

SqlConnection connCactus = new SqlConnection(connStr);
SqlCommand cmdPopulateFilterDropDowns = new SqlCommand( "dbo.MyStoredProc",
                                                        connCactus);
SqlDataReader rdrFilterSearch = null;
cmdPopulateFilterDropDowns.CommandType = CommandType.StoredProcedure;

connCactus.Open();
rdrFilterSearch = cmdPopulateFilterDropDowns
                      .ExecuteReader(CommandBehavior.CloseConnection);

return (rdrFilterSearch);

请帮助!

推荐答案

您曾经添加参数给SqlCommand的参数集合?你提到的那些不工作是那些需要输入参数,可以又在code你没有这样的事情:

Are you ever adding the parameters to the SqlCommand's Parameter collection? You mentioned that the ones that aren't working are the ones that take input params, yet in your code you don't have anything like this:

cmdPopulateFilterDropDowns.Parameters.AddWithValue(...);

这篇关于DataReader的不返回任何结果VS尚未存储过程返回多个结果集在SQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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