Using ExecuteReader

I have stored procedures, which like
SELECT * FROM settings ORDER BY [name]

Open in new window

SELECT [Value] FROM settings WHERE [Name]=@name

Open in new window

I wrote the code for the generic cases below but unfinished.
Thanks for advice.
public string ExecuteReader(string storedProcedure)
            return ExecuteReader(storedProcedure, null);

        public string ExecuteReader(string storedProcedure, Dictionary<string, object> parameters)
            string temp = string.Empty;
            using (SqlConnection conn = new SqlConnection(_connectionString))
                using (SqlCommand cmd = new SqlCommand(storedProcedure, conn))
                    cmd.CommandType = CommandType.StoredProcedure;
                    if (parameters != null)
                        foreach (string parameter in parameters.Keys)
                            cmd.Parameters.AddWithValue(parameter, parameters[parameter] ?? DBNull.Value);
                    using (SqlDataReader reader = cmd.ExecuteReader())
            return temp;

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

what do you need to do ?
what is missing from the code?
Chinmay PatelChief Technical NinjaCommented:
Are you looking for something like this?



Open in new window

zhshqzycAuthor Commented:
Yes. Do we need pass the column name?
And also if I used
select * from table

Open in new window

Then the program will return a list instead of a string.
We have to override the code?
Chinmay PatelChief Technical NinjaCommented:
no it will get all the records anyways so you have to process them one by one.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's something special you need to do? Why are you putting the values of all the results into a string and not manipulating the data?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.