Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I have a csv file and i need to read the csv file and add data from the csv. when i compile it gave me error:
Error 1 The name 'CreateValues' does not exist in the current context
 
Error 2 Operator '!=' cannot be applied to operands of type 'ReadCsvFile.DailyValues' and null
 
Error 3 The name 'rows' does not exist in the current context
 

 
 

 // reads stock values from csv file into a List
 public static List<DailyValues> GetStockValues(string filePath)
        {
            List<DailyValues> values = new List<DailyValues>();
          
            using (StreamReader reader = new StreamReader(filePath))
            {
                string line;
                DailyValues v;
                while ((line = reader.ReadLine()) != null)
                {
                    v = CreateValues(line);
                    if (v != null)
                        values.Add(v);
                }
            }
            return values;
// TODO: add the data from the csv file
            foreach (string row in rows)
            {
                if (string.IsNullOrEmpty(row)) continue;
                string[] cols = row.Split(',');
                DailyValues v = new DailyValues();
 
                v.Open = Convert.ToDecimal(cols[0]);
                v.High = Convert.ToDecimal(cols[1]);
                v.Low = Convert.ToDecimal(cols[2]);
                v.Close = Convert.ToDecimal (cols[3]);
                v.Volume = Convert.ToDecimal (cols[4]);
                v.AdjClose = Convert.ToDecimal(cols[5]);
                v.Date = Convert.ToDateTime(cols[6]);
                values.Add(v);
 

                return values;
Posted 8-Nov-12 19:11pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

>>Error 1 The name 'CreateValues' does not exist in the current context
 
Does CreateValues function exists. If it does, is it static. If not, either make it static or remove static from GetStockValues.
 
>>Error 2 Operator '!=' cannot be applied to operands of type 'ReadCsvFile.DailyValues' and null
 
Is DailyValues struct ? You cannot apply null check to struct.
Change following
if (v != null)
to
if (v != default(DailyValues))
 
>>Error 3 The name 'rows' does not exist in the current context
Where are rows ? It is missing. The error is self explanatory. Add a variable rows (which should have IEnumerable implemented on data type (some list/array is simple words))
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100