Wrox Programmer Forums
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2012, 02:50 PM
Authorized User
 
Join Date: Jul 2012
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Default Ch21: Reading a CSV

I'm trying to use the "Working with Comma-Separated Values" example program. However I'm not using a console application but a windows application.

I've taken the GetData method and placed it in Program.cs before Main. Then I copied the following two lines (from the example's Main) and placed it the form constructor:

Code:
        public Form1() {
            InitializeComponent();
               
            List<string> columns;
            List<Dictionary<string, string>> myData = GetData(out columns);
        }
and place the rest of the code inside Form1 (writing to a textbox instead of console):

Code:
        private void button1_Click(object sender, EventArgs e) {
            foreach (string column in columns) {
                textBox1.Text += column;
                //Console.Write("{0,-20}", column);
            }
            textBox1.Text += "\r\n";
            //Console.WriteLine();

            foreach (Dictionary<string, string> row in myData) {
                foreach (string column in columns) {
                    textBox1.Text += row[column];
                    //Console.Write("{0,-20}", row[column]);
                }
                textBox1.Text += "\r\n";
                //Console.WriteLine();
            }
            //Console.ReadKey();
        }
This give generates the error:

Quote:
Error 1 The name 'GetData' does not exist in the current context K:\visual_studio\learning_get_csv\learning_get_csv \Form1.cs
At this point I assume that the problem is that I'm no longer in "Program" but in a different class, "Form1", so I have to qualify the GetData method and change the line to:

Code:
List<Dictionary<string, string>> myData = Program.GetData(out columns);
Which changes the error to:

Quote:
Error 1 'learning_get_csv.Program.GetData(out System.Collections.Generic.List<string>)' is inaccessible due to its protection level K:\visual_studio\learning_get_csv\learning_get_csv \Form1.cs
Finally, grasping at straws, I make Program public:

Code:
static public class Program {
But this generates the same error. I'm dumb, I know, I just don't know how I'm dumb. Help? Please?

Thanks!!

Last edited by KaneT; July 16th, 2012 at 02:59 PM..
 
Old July 16th, 2012, 03:01 PM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

The GetData method must be public as well.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
The Following User Says Thank You to ChristianNagel For This Useful Post:
KaneT (July 16th, 2012)
 
Old July 16th, 2012, 04:37 PM
Authorized User
 
Join Date: Jul 2012
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Sir, if I could buy you a muffin I would. Making it public fixed it. :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
OutputTo .csv nspeelman Access 7 November 17th, 2008 01:37 PM
Code change; Page 1074; Ch21 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 August 3rd, 2006 09:18 AM
Reading a .csv file Dave Brown Beginning PHP 1 March 1st, 2005 10:57 AM
Reading a csv file agongar Beginning VB 6 2 February 9th, 2005 12:39 PM
Reading CSV in DataReader salimgbelim ADO.NET 0 November 3rd, 2003 07:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.