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. My SQL Import xls files

My SQL Import xls files

Scheduled Pinned Locked Moved C#
databasequestioncsharpmysqlhelp
5 Posts 3 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.
  • B Offline
    B Offline
    Burim Rama
    wrote on last edited by
    #1

    Hello everybody First sorry my english but i need som help. I have a website where i sal computer and other stof, every day i get i xls. file from one company with price list model number, description and other thing. Every product in my website has parnumber: thats unik. So i want to make a function in c# to update the price in mysql database because the price changes every day. How can i make a function like update table_name from c:\test.xls (take just price and partnumber from xls file ) where partnumber=(partnumber from xls) ? I hope really much you can help me.

    C M 2 Replies Last reply
    0
    • B Burim Rama

      Hello everybody First sorry my english but i need som help. I have a website where i sal computer and other stof, every day i get i xls. file from one company with price list model number, description and other thing. Every product in my website has parnumber: thats unik. So i want to make a function in c# to update the price in mysql database because the price changes every day. How can i make a function like update table_name from c:\test.xls (take just price and partnumber from xls file ) where partnumber=(partnumber from xls) ? I hope really much you can help me.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You will need to write code to parse the Excel file ( either export as csv, or use the Office interop stuff ), then write your SQL.

      Christian Graus Driven to the arms of OSX by Vista.

      B 1 Reply Last reply
      0
      • C Christian Graus

        You will need to write code to parse the Excel file ( either export as csv, or use the Office interop stuff ), then write your SQL.

        Christian Graus Driven to the arms of OSX by Vista.

        B Offline
        B Offline
        Burim Rama
        wrote on last edited by
        #3

        Thanks but do you have som code in c# i can use ?

        C 1 Reply Last reply
        0
        • B Burim Rama

          Thanks but do you have som code in c# i can use ?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Not really, no. Connecting to a db is trivial, and widely documented. Parsing a CSV is trivial, use File.ReadAllLines and the Split method on the string class to break each line into discreet items. Controlling Excel is also well documented.

          Christian Graus Driven to the arms of OSX by Vista.

          1 Reply Last reply
          0
          • B Burim Rama

            Hello everybody First sorry my english but i need som help. I have a website where i sal computer and other stof, every day i get i xls. file from one company with price list model number, description and other thing. Every product in my website has parnumber: thats unik. So i want to make a function in c# to update the price in mysql database because the price changes every day. How can i make a function like update table_name from c:\test.xls (take just price and partnumber from xls file ) where partnumber=(partnumber from xls) ? I hope really much you can help me.

            M Offline
            M Offline
            MacSpudster
            wrote on last edited by
            #5

            Burim, I had written an app to import excel files. That was some 3 years ago, so I no longer have the code. I did a google search for "C# import excel file into sql" and I found the same link I had used to write the code some 3 years ago. The link: http://davidhayden.com/blog/dave/archive/2006/05/31/2976.aspx[^] I recommend you use this link to do the following: 1) SQLBulkImport the Excel file into an import table (a table in the same database but that is only used for this purpose) 2) Call stored procedure that grabs the needed data from the import table and updates whatever table(s) you need to update. In my case, I had a Unique partNumber, too, so I would A) Mark records in my primary table as "inactive" (I use a tinyint with 1=inactive and 2=active) that were no longer in the import table B) Add new records from the import table into the primary table. C) Update records in the primary table with changed values in the import table (usually the description and price). Hope this helps.

            ASP ~ Apple Simply Performs

            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