Click here to Skip to main content
15,885,914 members
Home / Discussions / C#
   

C#

 
GeneralRe: A Layout Question, And A Bit More Pin
BillWoodruff21-May-12 18:10
professionalBillWoodruff21-May-12 18:10 
GeneralRe: A Layout Question, And A Bit More Pin
BillWoodruff22-May-12 3:47
professionalBillWoodruff22-May-12 3:47 
GeneralRe: A Layout Question, And A Bit More Pin
Roger Wright23-May-12 20:11
professionalRoger Wright23-May-12 20:11 
AnswerRe: A Layout Question, And A Bit More Pin
Gerry Schmitz21-May-12 13:12
mveGerry Schmitz21-May-12 13:12 
GeneralRe: A Layout Question, And A Bit More Pin
BillWoodruff21-May-12 17:42
professionalBillWoodruff21-May-12 17:42 
GeneralRe: A Layout Question, And A Bit More Pin
Gerry Schmitz21-May-12 21:02
mveGerry Schmitz21-May-12 21:02 
GeneralRe: A Layout Question, And A Bit More Pin
Roger Wright23-May-12 20:13
professionalRoger Wright23-May-12 20:13 
QuestionRow Not Found Or Changed Pin
Kevin Marois17-May-12 10:10
professionalKevin Marois17-May-12 10:10 
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

AnswerRe: Row Not Found Or Changed Pin
VJ Reddy17-May-12 21:22
VJ Reddy17-May-12 21:22 
Generalneed help Pin
Kurac117-May-12 9:09
Kurac117-May-12 9:09 
GeneralRe: need help Pin
Pete O'Hanlon17-May-12 9:13
mvePete O'Hanlon17-May-12 9:13 
GeneralRe: need help Pin
Kurac117-May-12 9:16
Kurac117-May-12 9:16 
GeneralRe: need help Pin
Pete O'Hanlon17-May-12 9:22
mvePete O'Hanlon17-May-12 9:22 
AnswerRe: need help Pin
Luc Pattyn17-May-12 11:57
sitebuilderLuc Pattyn17-May-12 11:57 
GeneralRe: need help Pin
fjdiewornncalwe17-May-12 11:16
professionalfjdiewornncalwe17-May-12 11:16 
QuestionNumericUpDown control increment value change Pin
Blubbo17-May-12 7:38
Blubbo17-May-12 7:38 
AnswerRe: NumericUpDown control increment value change Pin
OriginalGriff17-May-12 8:07
mveOriginalGriff17-May-12 8:07 
QuestionCannot Edit or Add Path to Reference File Pin
Xarzu17-May-12 6:47
Xarzu17-May-12 6:47 
AnswerRe: Cannot Edit or Add Path to Reference File Pin
Richard MacCutchan17-May-12 7:00
mveRichard MacCutchan17-May-12 7:00 
GeneralRe: Cannot Edit or Add Path to Reference File Pin
Xarzu17-May-12 7:31
Xarzu17-May-12 7:31 
AnswerRe: Cannot Edit or Add Path to Reference File Pin
Xarzu17-May-12 7:30
Xarzu17-May-12 7:30 
QuestionUser control as base class Pin
Ronny Portier17-May-12 4:50
Ronny Portier17-May-12 4:50 
AnswerRe: User control as base class Pin
BobJanova17-May-12 4:55
BobJanova17-May-12 4:55 
GeneralRe: User control as base class Pin
Ronny Portier17-May-12 5:27
Ronny Portier17-May-12 5:27 
AnswerRe: User control as base class Pin
RobCroll18-May-12 2:19
RobCroll18-May-12 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.