2

I have Visual Studio 2013 Ultimate and creating application of WPF.

I have to read the data from a SQL Server stored procedure by using SqlDataReader.

  1. Sometimes, if data exists, I can read data using sdr(sqldatareader).Read()

  2. But in the case when no data exists, I just select 'false' in stored procedure but I don't know how to read that string with having no column name by SqlDataReader.

enter image description here

4
  • You mean you do not know that you can access the columns using an ordinal (integer) instead of a name? And that is actually FASTER? Commented Feb 12, 2016 at 6:34
  • @TomTom How can I read column name? Commented Feb 12, 2016 at 6:47
  • You do know there is a documentation that can show you every method for a given class? I would strongly suggest you open it and read it TOP TO BOTTOM. Commented Feb 12, 2016 at 6:51
  • Appreciate your answer as well @TomTom Commented Feb 12, 2016 at 6:57

1 Answer 1

4

You can do this.

reader.GetString(0); //0 stands for "the 0'th column"
Sign up to request clarification or add additional context in comments.

7 Comments

You are right but what about the data if there is exist. How can i read that because on condition check is it false or not that time I will get an error for reading coming table data.
You need to differentiate the data exist and not exist, an example, you may check DataReader has more than one row and one columns.
Yes the solution is good but how to read columns count or rows count?
You have an option to check column count, reader.FieldCount returns column count.
Ohhh yes great thanks @Hari Prasad and one last question can i read number of rows as well?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.