Domanda

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 :)

È stato utile?

Soluzione 3

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();
     }

Altri suggerimenti

Here are the steps:

1- right-click your database and choose task/export data,

2- Datasource: flat file

3- delimiter : tab

next in the wizard...

If you are using MS SQL, you should look at the BCP program.

http://msdn.microsoft.com/en-us/library/aa174646(v=sql.80).aspx

or the BULK INSERT command

If you have installed mysql with the WAMP server, the easiest way would be:

  1. Assuming your DB is on your own computer, open PHPMyAdmin on the browser like this: localhost/phpmyadmin

  2. Open your mysql DB. If you don't have it already, create one. i.e., only the DB (without tables)

  3. With the DB active, use the IMPORT feature on phpmyadmin. Find the button on top of the screen.

  4. Specify your file to import and indicate the delimiting character as the TAB. By default it is a COMMA.

You can now directly have your records in the DB.

One point though... Some phpmyadmin setups by default have a restriction on the file size.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top