当前位置: 首页>>代码示例>>C#>>正文


C# CsvFileReader.ReadRow方法代码示例

本文整理汇总了C#中CsvFileReader.ReadRow方法的典型用法代码示例。如果您正苦于以下问题:C# CsvFileReader.ReadRow方法的具体用法?C# CsvFileReader.ReadRow怎么用?C# CsvFileReader.ReadRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvFileReader的用法示例。


在下文中一共展示了CsvFileReader.ReadRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: saveButton_Click

        private void saveButton_Click(object sender, EventArgs e)
        {
            FileStream aStreamForReading = new FileStream(fileLocation, FileMode.Open);
            CsvFileReader aReader = new CsvFileReader(aStreamForReading);
            List<string> aRecord = new List<string>();

            while (aReader.ReadRow(aRecord))
            {

                string regNo = aRecord[0];
                if (regNoTextBox.Text == regNo)
                {
                    MessageBox.Show(@"Reg no already exists");
                    aStreamForReading.Close();
                    return;
                }
            }
            aStreamForReading.Close();

            FileStream aStream = new FileStream(fileLocation, FileMode.Append);
            CsvFileWriter aWriter = new CsvFileWriter(aStream);
            List<string> aStudentRecord = new List<string>();
            aStudentRecord.Add(regNoTextBox.Text);
            aStudentRecord.Add(nameTextBox.Text);
            aWriter.WriteRow(aStudentRecord);
            aStream.Close();
        }
开发者ID:SyedArifulIslamEmon,项目名称:BasisTraining,代码行数:27,代码来源:StudentRecordKeepingUI.cs

示例2: showButton_Click

        private void showButton_Click(object sender, EventArgs e)
        {
            FileStream aStream = new FileStream(fileLocation, FileMode.OpenOrCreate);
            CsvFileReader aReader = new CsvFileReader(aStream);
            List<string> aPeronRecord = new List<string>();


            personListView.Items.Clear();



            while (aReader.ReadRow(aPeronRecord))
            {
                ListViewItem listViewItem = new ListViewItem(new string[]
                {
                    aPeronRecord[0],
                    aPeronRecord[1],
                    aPeronRecord[2],
                    aPeronRecord[3],
                    aPeronRecord[4]
                
                }
            );
                personListView.Items.Add(listViewItem);
            }
            aStream.Close();
        }
开发者ID:saddamhossain,项目名称:Project,代码行数:27,代码来源:Form1.cs

示例3: EventPointsReader

        public EventPointsReader(String filePath, Boolean skipHeader)
        {
            this.EventPoints = new List<EventPoint>();

            CsvFileReader reader = new CsvFileReader(filePath);

            Boolean headerSkipped = false;

            while (true)
            {
                CsvRow row = new CsvRow();
                if (reader.ReadRow(row))
                {
                    if ((skipHeader && headerSkipped) ||
                        !skipHeader)
                    {
                        EventPoint ep = new EventPoint();
                        ep.LongCode = row[0];
                        ep.ShortCode = row[1];
                        ep.DateTimeFrom = DateTime.ParseExact(row[2], "yyyy-MM-dd HH:mm:ss.fff", null);
                        ep.DateTimeTo = DateTime.ParseExact(row[3], "yyyy-MM-dd HH:mm:ss.fff", null);
                        ep.RangeMax = Convert.ToDouble(row[4]);
                        ep.RangeMin = Convert.ToDouble(row[5]);

                        this.EventPoints.Add(ep);
                    }
                    headerSkipped = true;
                }
                else
                {
                    break;
                }
            }
        }
开发者ID:HongSeokHwan,项目名称:legacy,代码行数:34,代码来源:EventPointsReader.cs

示例4: readPlayers

 public Dictionary<string, Player> readPlayers()
 {
     Dictionary<string, Player> listPlayers = new Dictionary<string, Player>();
     using (CsvFileReader reader = new CsvFileReader(file))
     {
         CsvRow row = new CsvRow();
         while (reader.ReadRow(row))
         {
             listPlayers.Add(row[Constants.FName], new Player(row[Constants.FName], boolFromString(row[Constants.FBoolTerran]),
                 boolFromString(row[Constants.FBoolZerg]), boolFromString(row[Constants.FBoolProtoss]), boolFromString(row[Constants.FBoolRandom])));
             Player temp = listPlayers[row[Constants.FName]];
             int.TryParse(row[Constants.FVictoryTerran], out temp.Victory[Constants.Terran]);
             int.TryParse(row[Constants.FVictoryZerg], out temp.Victory[Constants.Zerg]);
             int.TryParse(row[Constants.FVictoryProtoss], out temp.Victory[Constants.Protoss]);
             int.TryParse(row[Constants.FVictoryRandom], out temp.Victory[Constants.Random]);
             int.TryParse(row[Constants.FDefeatTerran], out temp.Defeat[Constants.Terran]);
             int.TryParse(row[Constants.FDefeatZerg], out temp.Defeat[Constants.Zerg]);
             int.TryParse(row[Constants.FDefeatProtoss], out temp.Defeat[Constants.Protoss]);
             int.TryParse(row[Constants.FDefeatRandom], out temp.Defeat[Constants.Random]);
             int.TryParse(row[Constants.FEloTerran], out temp.Elo[Constants.Terran]);
             int.TryParse(row[Constants.FEloZerg], out temp.Elo[Constants.Zerg]);
             int.TryParse(row[Constants.FEloProtoss], out temp.Elo[Constants.Protoss]);
             int.TryParse(row[Constants.FEloRandom], out temp.Elo[Constants.Random]);
         }
     }
     return listPlayers;
 }
开发者ID:dosimont,项目名称:sc2_matchmaker,代码行数:27,代码来源:PlayerReader.cs

示例5: loadSNPSPToolStripMenuItem_Click

        private void loadSNPSPToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _openFileDialog.FileName = "SNPCC.csv";
            _openFileDialog.Filter = "csv files (*.csv)|*.csv";
            _openFileDialog.DefaultExt = "txt";
            _openFileDialog.FilterIndex = 2;
            _openFileDialog.AddExtension = true;
            if (_openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = _openFileDialog.FileName;
                CsvFileReader csv = new CsvFileReader(fileName);
                char[] _separators = new char[] { '\n', '"', ',' };
                CsvRow row = new CsvRow();
                bool entering = true;
                while (entering == true)
                {
                    entering = csv.ReadRow(row);
                    staters.Add(new Stater(row[1], row[0]));
                    char[] bar = row[2].ToCharArray();
                    string bs = Convert.ToString(bar[0]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
                    staters[staters.Count - 1].Barcode = Convert.ToInt32(bs);
                    staters[staters.Count - 1].City = row[3];
                    staters[staters.Count - 1].County = row[4];
                }

                csv.Close();
                staters.RemoveAt(staters.Count - 1);
                List<Stater> testing = staters;
            }
        }
开发者ID:ThaddeusT,项目名称:StaterPhotoSuite,代码行数:30,代码来源:Form1.cs

示例6: CsvLoadTripRoutes

        public static void CsvLoadTripRoutes(string filename, bool lngFirst)
        {
            // load trip routes
            Dictionary<string, LinkedList<Waypoint>> routes = new Dictionary<string, LinkedList<Waypoint>>();
            using (CsvFileReader reader = new CsvFileReader(filename))
            {
                CsvRow row = new CsvRow();
                while (reader.ReadRow(row, ','))
                {
                    string routeID = row[0];
                    double distance = 0;
                    double lat = Convert.ToDouble(lngFirst ? row[2] : row[1]);
                    double lng = Convert.ToDouble(lngFirst ? row[1] : row[2]);
                    if (routes.ContainsKey(routeID))
                        distance = routes[routeID].First.Value.GetDistance(new Location(lat, lng, "null"));
                    Waypoint waypoint = new Waypoint(lat, lng, TimeSpan.Parse(row[3]), distance, row[4].Replace("\"", ""));

                    // Scenario #1
                    if (!routes.ContainsKey(routeID))
                        routes[routeID] = new LinkedList<Waypoint>();
                    routes[routeID].AddLast(waypoint);

                }
            }
            foreach (LinkedList<Waypoint> w in routes.Values)
            {
                Route r = new Route(w.ToArray());
                string key = Route.GetKey(r.start, r.end);
                MapTools.routes.Add(key, r);
            }
        }
开发者ID:TripThru,项目名称:Gateway,代码行数:31,代码来源:1397817436$MapTools.cs

示例7: CsvToStringQueries

        public CsvToStringQueries(String fileName, String tableName)
        {
            this._fileName = fileName;
            this._tableName = tableName;
            CsvFileReader reader = new CsvFileReader(fileName);
            CsvRow header = new CsvRow();
            reader.ReadRow(header);

            while (true)
            {
                if (reader.EndOfStream)
                {
                    break;
                }

                CsvRow body = new CsvRow();
                reader.ReadRow(body);
                String query = CreateQuery(body, tableName);

                this._queries.Add(query);
            }
        }
开发者ID:HongSeokHwan,项目名称:legacy,代码行数:22,代码来源:CsvToStringQueries.cs

示例8: DeserializeRecordsCsv

        public static IEnumerable<Record> DeserializeRecordsCsv(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(
                    "The file at the specified path could not be found.");
            }

            List<Record> retList = new List<Record>();

            using (CsvFileReader reader = new CsvFileReader(path))
            {
                CsvRow headers = new CsvRow();
                reader.ReadRow(headers);
                if (headers != ExpectedColumnHeaders.ToList())
                {
                    throw new Exception("CSV file headers are invalid.");
                }

                CsvRow row = new CsvRow();
                while (reader.ReadRow(row))
                {
                    retList.Add(new Record
                    {
                        Id = Convert.ToInt32(row[0]),
                        GivenName = row[1],
                        Surname = row[2],
                        StreetAddress = row[3],
                        City = row[4],
                        State = row[5],
                        ZipCode = row[6],
                        EmailAddress = row[7],
                        TelephoneNumber = row[8]
                    });
                }
            }

            return retList;
        }
开发者ID:adam-henley,项目名称:datastructure-exploration,代码行数:39,代码来源:Utility.cs

示例9: showButton_Click

        private void showButton_Click(object sender, EventArgs e)
        {
            FileStream aStream = new FileStream(fileLocation, FileMode.Open);
            CsvFileReader aReader = new CsvFileReader(aStream);
            List<string> aStudentRecord = new List<string>();

            studentListBox.Items.Clear();

            while (aReader.ReadRow(aStudentRecord))
            {
                string regNo = aStudentRecord[0];
                string name = aStudentRecord[1];
                studentListBox.Items.Add(regNo + " " + name);
            }
            aStream.Close();
        }
开发者ID:SyedArifulIslamEmon,项目名称:BasisTraining,代码行数:16,代码来源:StudentRecordKeepingUI.cs

示例10: btnEntryShow_Click

        private void btnEntryShow_Click(object sender, EventArgs e)
        {
            FileStream aStream = new FileStream(fileLocation, FileMode.Open);
            CsvFileReader aReader = new CsvFileReader(aStream);

            List<string> record = new List<string>();

            while (aReader.ReadRow(record))
            {
                string bill = record[0];
                double aBill = Convert.ToDouble(bill);
                aBill += aBill;
                txtBoxTotalExpns.Text = aBill.ToString();
            }
            aStream.Close();
        }
开发者ID:SyedArifulIslamEmon,项目名称:BasisTraining,代码行数:16,代码来源:DailyEntryUI.cs

示例11: saveButton_Click

        private void saveButton_Click(object sender, EventArgs e)
        {

            FileStream aStream = new FileStream(fileLocation, FileMode.OpenOrCreate);
           
            CsvFileReader aReader = new CsvFileReader(aStream);
            List<string> aPeronRecord = new List<string>();


            //personListView.Items.Clear();



            while (aReader.ReadRow(aPeronRecord))
            {
                if (aPeronRecord[2] == personalCnTextBox.Text)
                {
                    MessageBox.Show("conflict");

                    aStream.Close();
                    return;
                }
            }
            aStream.Close();



            FileStream aStream2 = new FileStream(fileLocation, FileMode.Append);
            CsvFileWriter aWriter = new CsvFileWriter(aStream2);
            List<string> aPersonRecod = new List<string>();

            aPersonRecod.Add(nameTextBox.Text);
            aPersonRecod.Add(emailTextBox.Text);
            aPersonRecod.Add(personalCnTextBox.Text);
            aPersonRecod.Add(homeCnTextBox.Text);
            aPersonRecod.Add(homeAddressTextBox.Text);

            aWriter.WriteRow(aPersonRecod);

            aStream2.Close();

            
                    


        }
开发者ID:saddamhossain,项目名称:Project,代码行数:46,代码来源:Form1.cs

示例12: CreateInsertQueries

        public List<string> CreateInsertQueries(string fileName)
        {
            List<string> queries = new List<string>();

            CsvFileReader reader = new CsvFileReader(fileName);

            bool firstRowRead = false;
            while (true)
            {
                if (reader.EndOfStream)
                {
                    break;
                }

                CsvRow row = new CsvRow();
                reader.ReadRow(row);

                if (!firstRowRead)
                {
                    firstRowRead = true;
                    continue;
                }

                if (row[4].CompareTo("USD") == 0)
                {
                    continue;
                }

                string ticker = String.Format("USD{0} Curncy", row[4]);
                string desc = String.Format("{0} / 1 usd currency", row[0]);
                string queryDelete = String.Format(
                    "delete from product_list where ticker = '{0}'", ticker);
                string queryInsert = String.Format(
                    "insert into product_list values ('{0}', 'USD', '{1}', 0, 0, 'Index')",
                    ticker, desc);
                queries.Add(queryDelete);
                queries.Add(queryInsert);
            }

            return queries;
        }
开发者ID:HongSeokHwan,项目名称:legacy,代码行数:41,代码来源:CurncyTickerQueryGenerator.cs

示例13: Get

        // GET api/product/5
        public IEnumerable<ProductItem> Get(int id)
        {
            List<ProductItem> productList = new List<ProductItem>();

            int rowid = 0;
            // Read sample data from CSV file
            using (CsvFileReader reader = new CsvFileReader(productfilePath))
            {
                CsvRow row = new CsvRow();

                while (reader.ReadRow(row))
                {
                    if (rowid > 0)
                    {
                        productList.Add(new ProductItem() { ProductId = Convert.ToInt32(row[0]), Name = row[1], ImageUrl = row[2], Price = Convert.ToDouble(row[3]), Calories = Convert.ToInt32(row[4]) });
                    }
                    rowid++;
                }
            }
            return productList.FindAll(product=>product.ProductId==id);
        }
开发者ID:talajiam,项目名称:Hackathon,代码行数:22,代码来源:ProductController.cs

示例14: ReadCSVFile

        /// <summary> Reads the earthquakes from a csv file and adds them to a clusterer. The clusterer then groups
        /// them to clusters. </summary>
        /// <returns> Documentation in progress... </returns>
        public static IEnumerable<Location> ReadCSVFile()
        {
            var filePath = AppDomain.CurrentDomain.BaseDirectory + @"wikilocations25000.csv";
            using (var reader = new CsvFileReader(filePath, (char)0x09))
            {
                var row = new CsvRow();
                while (reader.ReadRow(row))
                {
                    if (row.Count < 3)
                        continue;

                    double x, y;
                    bool parsed = Double.TryParse(row[2], NumberStyles.Float, CultureInfo.InvariantCulture, out x);
                    x = parsed ? x : Double.NaN;
                    parsed = Double.TryParse(row[1], NumberStyles.Float, CultureInfo.InvariantCulture, out y);
                    y = parsed ? y : Double.NaN;
                    var post = new Location { Title = row[0], Coordinate = new Point(x, y) };
                    yield return post;
                }
            }
        }
开发者ID:MuffPotter,项目名称:xservernet-bin,代码行数:24,代码来源:Window1.xaml.cs

示例15: ReadFile

        /// <summary>
        /// Reads the csv file, decides what type of words are stored there and put them into Output list
        /// </summary>
        /// <param name="worker"></param>
        public void ReadFile(BackgroundWorker worker)
        {
            // Initialize lines numbers
            int oldProgress = 0;
            LinesNumber = File.ReadLines(this.filename).Count(); // don't need to close, it closes automatically
            LinesProcessed = 0;
            try
            {
                /* Using statement will call a Disposable object on the reader object after exiting using scope
                   This will ensure secure resources disposal
                   Use this construction for reading files or any other resource-sensitive objects */
                using (CsvFileReader reader = new CsvFileReader(this.filename))
                {
                    CsvRow row = new CsvRow();
                    while (reader.ReadRow(row))
                    {
                        ParseRowList(row);

                        // Calculate and report progress in percentage
                        LinesProcessed++;
                        double progress = ((double)LinesProcessed / (double)LinesNumber) * 100;

                        // report only if there was was a whole change in progress, 1->2, 56->57 etc.
                        if ((int)progress != oldProgress)
                        {
                            worker.ReportProgress((int)progress); // Progress will be reported only 100 times
                        }

                        oldProgress = (int)progress;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
开发者ID:niyazmohammad,项目名称:Dictionary,代码行数:41,代码来源:FileReader.cs


注:本文中的CsvFileReader.ReadRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。