473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

C# Reading Data into Static Array

384 256MB
I have this code on load:
Expand|Select|Wrap|Line Numbers
  1. Reader = command.ExecuteReader();
  2. Reader.Read();
  3. while (Reader.NextResult)
  4. {
  5.     session.gameList = Reader.GetValue(0).ToString();
  6. }
I'm trying to read it into a static array defined in this class called session:
Expand|Select|Wrap|Line Numbers
  1. class session
  2. {
  3.         private static string[] gamelist;
  4.  
  5.         public static string[] gameList
  6.         {
  7.             get { return gamelist; }
  8.             set { gamelist = value; }
  9.         }
  10. }
Can't get it to work, i'm thinking i may need to loop it somewhere but unsure as where!?
Sep 27 '08 #1
3 1440
tlhintoq
3,525 Expert 2GB
"I can't get it to work" is a bit vague. Do you get an error message? Exception not handled? Results just different than what you expect?

session.gameList = Reader.GetValue(0).ToString();

What is it you think this line is going to do?
Reason I ask is because you keep setting it's value to something new.
Notice I didn't say "adding to its value", or setting the value of one if its elements.

You have a string array called gamelist. You need to access the elements of the array. For example...
sesson.gameList[nIndex] = Reader.GetValue(0).ToString();
Sep 28 '08 #2
Curtis Rutland
3,256 Expert 2GB
You have a string array called gamelist. You need to access the elements of the array. For example...
sesson.gameList[nIndex] = Reader.GetValue(0).ToString();
I think a better object to use would be a List or an Array so that you don't have to predefine the length.
Sep 28 '08 #3
Plater
7,872 Expert 4TB
Well I would say it throws the error, cannot convert string to string[]
Since you are trying to do this:
session.gameList = Reader.GetValue(0).ToString();

where session.gameList is a string[] and Reader.GetValue(0).ToString() is just a string. And you do not supply an index into the string[].

It *is* possible to do this with a straight static array, but it would be just as easy to use a List or other collection object as mentioned. then if need be you can just use the .ToArray() function of the collection to get a string[]
Sep 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
1
by: Jón Sveinsson | last post by:
Hello everyone I have been able to read data from binary files to filestrean, the data in the files are structured, what I'm trying to do is to loop through the binary files and add data to my...
0
by: ponchorage | last post by:
I'm trying to read the toc of an audio cd programmatically using the ASPI functions in C#. I've Dllimported the necessary functions. I can get all kinds of information about the drives but I can't...
7
by: tackleberi | last post by:
hi, im having some trouble reading a file into java and then storing it in an array here the code i have so far: import java.io.FileNotFoundException; import java.io.FileReader; import...
21
by: Stephen.Schoenberger | last post by:
Hello, My C is a bit rusty (.NET programmer normally but need to do this in C) and I need to read in a text file that is setup as a table. The general form of the file is 00000000 USNIST00Z...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.