Retrieving data from SqlDataReader to a string array
-
Hi all, i have written a query in SQL which returns multiple rows. i used a SqlDataReader to capture the result. what i want is to retrieve data from this DataReader and store it in a string array. this is how iam proceeding.. string[] arr = new string[10]; int index=0; while(reader.Read()) { object[] values = new object[reader.FieldCount]; reader.GetValues(value); vlaues.CopyTo(arr,index); index++; } this is not working and i know tat CopyTo cannot be used in this context, but i just dont have any idea what to use. I need to use this string array in an if-else condition where i need to compare each string in that array with a specified string and return a boolean value. i would be grateful to anybody who can help me in this regard. i have been working on this for almost 2 days without a breakthrough.
Sonu
-
Hi all, i have written a query in SQL which returns multiple rows. i used a SqlDataReader to capture the result. what i want is to retrieve data from this DataReader and store it in a string array. this is how iam proceeding.. string[] arr = new string[10]; int index=0; while(reader.Read()) { object[] values = new object[reader.FieldCount]; reader.GetValues(value); vlaues.CopyTo(arr,index); index++; } this is not working and i know tat CopyTo cannot be used in this context, but i just dont have any idea what to use. I need to use this string array in an if-else condition where i need to compare each string in that array with a specified string and return a boolean value. i would be grateful to anybody who can help me in this regard. i have been working on this for almost 2 days without a breakthrough.
Sonu
Okay - I can see that your code is not working. I think it is because you don't really understand what the GetValues() method is returning. So, I need the answer to the following questions: * What is SQL Server returning? How many rows? How many columns? * What do you want your output to be?
*** Developer Day 4 in Reading, England on 2nd December 2006 - Registration Now Open *** Upcoming Scottish Developers events: * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog | Photos