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. Row Not Found Or Changed

Row Not Found Or Changed

Scheduled Pinned Locked Moved C#
csharpdatabaselinqhelpquestion
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.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I'm importing and updating a parts table from a CSV file into a table using Linq To Sql:

    public int ImportPartsFile(string FileName)
    {
    using (SparesDataContext dc = getDataContext())
    {
    using (TextFieldParser tfp = new TextFieldParser(FileName))
    {
    int lineNo = 0;
    int imported = 0;
    int updated = 0;

            tfp.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
            tfp.SetDelimiters(",");
    
            string\[\] words;
    
            while (!tfp.EndOfData)
            {
                words = tfp.ReadFields();
                lineNo++;
    
                string partNo = words\[0\];
                string description = words\[1\];
                string priceString = words\[2\];
    
                if (partNo.Trim() == string.Empty || priceString == string.Empty)
                {
                    continue;
                }
    
                priceString = priceString.Replace("$", "");
                int price = Convert.ToInt32(Convert.ToDecimal(priceString));
    
                var part = (from p in dc.tblHPParts
                            where p.PartNumber.Trim().ToLower() == partNo.Trim().ToLower()
                            select p).FirstOrDefault();
    
                if (part == null)
                {
                    tblHPPart partRow = new tblHPPart
                    {
                        PartNumber = partNo,
                        Description = description,
                        Price = price
                    };
    
                    dc.tblHPParts.InsertOnSubmit(partRow);
                    dc.SubmitChanges();
                    imported++;
                }
                else
                {
                    part.Price = price;
                    dc.SubmitChanges();
                    updated++;
                }
            }
    
            return imported;
        }
    }
    

    }

    At the point where I do

    else
    {
    part.Price = price;
    dc.SubmitChanges();
    updated++;
    }

    if get

    Row not found or changed

    There are 3676 lines in the CSV file, and it dies on line 40

    022N02177 ,XEROX PICKUP ROLLER ,$13

    Anyone know what's wrong?

    If it's not broken, fix it until it is

    V 1 Reply Last reply
    0
    • K Kevin Marois

      I'm importing and updating a parts table from a CSV file into a table using Linq To Sql:

      public int ImportPartsFile(string FileName)
      {
      using (SparesDataContext dc = getDataContext())
      {
      using (TextFieldParser tfp = new TextFieldParser(FileName))
      {
      int lineNo = 0;
      int imported = 0;
      int updated = 0;

              tfp.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
              tfp.SetDelimiters(",");
      
              string\[\] words;
      
              while (!tfp.EndOfData)
              {
                  words = tfp.ReadFields();
                  lineNo++;
      
                  string partNo = words\[0\];
                  string description = words\[1\];
                  string priceString = words\[2\];
      
                  if (partNo.Trim() == string.Empty || priceString == string.Empty)
                  {
                      continue;
                  }
      
                  priceString = priceString.Replace("$", "");
                  int price = Convert.ToInt32(Convert.ToDecimal(priceString));
      
                  var part = (from p in dc.tblHPParts
                              where p.PartNumber.Trim().ToLower() == partNo.Trim().ToLower()
                              select p).FirstOrDefault();
      
                  if (part == null)
                  {
                      tblHPPart partRow = new tblHPPart
                      {
                          PartNumber = partNo,
                          Description = description,
                          Price = price
                      };
      
                      dc.tblHPParts.InsertOnSubmit(partRow);
                      dc.SubmitChanges();
                      imported++;
                  }
                  else
                  {
                      part.Price = price;
                      dc.SubmitChanges();
                      updated++;
                  }
              }
      
              return imported;
          }
      }
      

      }

      At the point where I do

      else
      {
      part.Price = price;
      dc.SubmitChanges();
      updated++;
      }

      if get

      Row not found or changed

      There are 3676 lines in the CSV file, and it dies on line 40

      022N02177 ,XEROX PICKUP ROLLER ,$13

      Anyone know what's wrong?

      If it's not broken, fix it until it is

      V Offline
      V Offline
      VJ Reddy
      wrote on last edited by
      #2

      As observed in the data of line 40 given above in 022N02177 0 is zero instead of letter 'O'. But if that is the case and the part number is not found then the execution should go in to the if (part == null) block. But I want to share what I have noticed and please see whether the issue is because of that.

      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