Search code examples
asp.netsql-serverflat-filecsv

Tab-delimited flat file to SQL


I have a Tab-delimited flat file which i need to pull data from and update a table in my MS-SQL database.

Does anyone have any details on how i would go about doing this? Maybe a site or a tutorial somewhere?

Thanks in advance.

Update: Basically Amazon returns a Tab-delimited flat file, which i need to pull data from, then use that data to update my database. I already know how to export data from a MS SQL database :)


Solution

  • I managed to work out what was needed, using the code below. Added as a reference incase someone needs something similar.

    try
         {
            //start with the second row
            string[] rowRow = row.Split('\t');
    
            string sku = rowRow[0].Trim();
            string qty = rowRow[1].Trim();
            decimal price = Convert.ToDecimal(rowRow[2].Trim());
            string asin = rowRow[3].Trim();
    
            int pcType = dc.productCodeTypes.Where(c => c.length == asin.Length).FirstOrDefault().id;
    
            //Save to DB
            abcProduct aUpdate = dc.abcProducts.Single(p => p.sku == sku);
            if (aUpdate.asin == asin) { }
               else { aUpdate.asin = asin; }
            if (aUpdate.codeType == pcType) { }
               else { aUpdate.codeType = pcType; }
            if (aUpdate.amzPrice == price) { }
               else { aUpdate.amzPrice = price; }
            dc.SubmitChanges();
         }