Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Retrieving data from SqlDataReader to a string array

Retrieving data from SqlDataReader to a string array

Scheduled Pinned Locked Moved C#
databasedata-structureshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sonu T
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • S Sonu T

      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

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups