Datareader does not return any results in VS, but the stored procedure returns several result sets in Sql Server

I am having problems getting results from my datareader in visual studio 2008. I have several saved Procs in the same database. I can get values ​​from those that do not receive input parameters. However, when I use the executreReader () method for a stored procedure with input parameters, I get an empty data directory. After examining the result collection, the message "IEnumerable does not return any results." I'm confusing since I can execute stored procs in sql server and return result sets. Previously, I could retrieve strings from these stored procedures in Visual Studio, but apparently it just stopped working one fine day.

I tried to use the dataadapter to populate the data set with my results and use the executereader () method to get sqldatareader, and yet I am not getting any results. No exceptions are thrown. My parameters are all named correctly, but I should be able to call these stored procedures without parameters and return an unfiltered result set. Currently Used Code:

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);

Please, help!

+5
source share
8 answers

Do you ever add parameters to the SqlCommand parameter collection? You mentioned that those that don't work are those that take input parameters, but in your code you have nothing like this:

cmdPopulateFilterDropDowns.Parameters.AddWithValue(...);
+5
source

. , , , , , , . .

+5

SQL , , , . ? , .

BFree , AddWtihValue() Add(). , SqlParameter, , .Add(). , .Add(), (int) 0 - ...

+2

, , , , .Read()? , , , .

+2

, , , , - .

SQL SQL, SQL Server, Management Studio, . SQL inline sproc, , Visual Studio - ASP.Net, DataReader.

SQL Management Studio, DataReader Visual Studio? , . Management Studio SQL . Visual Studio , , .

, . , SQL/sproc JOIN , . : , .

+2

directiondirection sqlParam .

mySqlParam.Direction = ParameterDirection.ReturnValue;

, :

    SqlParameter mySqlParam = new SqlParameter();
    mySqlParam.ParameterName = "@ID";
    mySqlParam.SqlDbType = SqlDbType.int;
    mySqlParam.Direction = ParameterDirection.ReturnValue;

    SqlParameter mySqlParam = new SqlParameter();
    mySqlParam.ParameterName = "@Name";
    mySqlParam.SqlDbType = SqlDbType.NVarChar;
    mySqlParam.Direction = ParameterDirection.ReturnValue;


    SqlParameter mySqlParam = new SqlParameter();
    mySqlParam.ParameterName = "@Address";
    mySqlParam.SqlDbType = SqlDbType.NVarChar;
    mySqlParam.Direction = ParameterDirection.ReturnValue;

mySqlParam.ParameterName .

, ( ):

int.Parse(dataReader["ID"]);
dataReader["name"].ToString();
dataReader["address"].ToString();

dataReader[""].ToString(); coloumame .

+1

"IEnumerable return no results"? , DataReader?

,

rdrFilterSearch.GetString(0);

?

0

reader.ExecuteNonQuery() 

0

All Articles