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. Web Development
  3. ASP.NET
  4. Import Dynamic exel to sqlserver

Import Dynamic exel to sqlserver

Scheduled Pinned Locked Moved ASP.NET
questionhelp
5 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.
  • A Offline
    A Offline
    amina89
    wrote on last edited by
    #1

    Hi, I try to import Excel files to sqlserver problem is that the number and the titles of columns are dynamic.How can i do that?by code. Thank you

    T 1 Reply Last reply
    0
    • A amina89

      Hi, I try to import Excel files to sqlserver problem is that the number and the titles of columns are dynamic.How can i do that?by code. Thank you

      T Offline
      T Offline
      T M Gray
      wrote on last edited by
      #2

      Do you want a new table each time? You could use a select into SQL statement. What are you going to do with the data? A bunch of random SQL tables with random columns doesn't sound very useful.

      A 1 Reply Last reply
      0
      • T T M Gray

        Do you want a new table each time? You could use a select into SQL statement. What are you going to do with the data? A bunch of random SQL tables with random columns doesn't sound very useful.

        A Offline
        A Offline
        amina89
        wrote on last edited by
        #3

        thank you T M Gray, I have this problem for almost a month. I work on an intranet site management reviews of students. I want to help the manager module to enter student markes . the problem is that the subjects of a module are dynamic ,I tried a gridview in edit mode but I failed to create the columns dynamically and insert all data at once in the DB. Now I have an excel file generated by a dynamic sql query containing students of a module but I do not know how import it to the database because the column names and number change . the table: reveiw : id_student________id_subjects______marks table subject: id_subject_______name_subject______id_module the excel file columns: id_student_____name_student_____name_subject1____name_subject2.... in the name_subjet1 i have de marks of subject1. I do not know what to do ,is there another solution? Thanks.

        T 1 Reply Last reply
        0
        • A amina89

          thank you T M Gray, I have this problem for almost a month. I work on an intranet site management reviews of students. I want to help the manager module to enter student markes . the problem is that the subjects of a module are dynamic ,I tried a gridview in edit mode but I failed to create the columns dynamically and insert all data at once in the DB. Now I have an excel file generated by a dynamic sql query containing students of a module but I do not know how import it to the database because the column names and number change . the table: reveiw : id_student________id_subjects______marks table subject: id_subject_______name_subject______id_module the excel file columns: id_student_____name_student_____name_subject1____name_subject2.... in the name_subjet1 i have de marks of subject1. I do not know what to do ,is there another solution? Thanks.

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          It looks to me like you need to redo the query that generates the excel file. The relationships between student, subject, and module aren't completely clear to me.

          A 1 Reply Last reply
          0
          • T T M Gray

            It looks to me like you need to redo the query that generates the excel file. The relationships between student, subject, and module aren't completely clear to me.

            A Offline
            A Offline
            amina89
            wrote on last edited by
            #5

            Hi, this is the query that generates excel: DECLARE @MATIERE nvarchar(max) SELECT @MATIERE = STUFF( ( select distinct ',[' + LIBELLE_MATIERE + ']' from MATIERE where CODE_MODULE =11 for xml path('') ), 1,1,'') DECLARE @SQL nvarchar(max) SELECT @SQL = N' select * from ( SELECT ETUDIANT.NUM_INSCRIPTION, ETUDIANT.NOM_PRENOM_ETUDIANT_ARABE,EXAMEN.CODE, EXAMEN.NOTE, MATIERE.LIBELLE_MATIERE FROM ETUDIANT INNER JOIN EXAMEN ON ETUDIANT.NUM_INSCRIPTION = EXAMEN.NUM_INSCRIPTION INNER JOIN CAPITALISE_MODULE ON ETUDIANT.NUM_INSCRIPTION = CAPITALISE_MODULE.NUM_INSCRIPTION INNER JOIN MATIERE ON EXAMEN.CODE_MATIERE = MATIERE.CODE_MATIERE INNER JOIN MODULE ON CAPITALISE_MODULE.CODE_MODULE = MODULE.CODE_MODULE AND MATIERE.CODE_MODULE = MODULE.CODE_MODULE WHERE (CAPITALISE_MODULE.CODE_MODULE = 11) AND (CAPITALISE_MODULE.CODE_TYPE_RELATION_MODULE = 1) ) Data PIVOT ( SUM(NOTE) FOR LIBELLE_MATIERE IN ( ' + @MATIERE + ' ) ) PivotTable ' exec sp_executesql @SQL there is a relationship"review" between the student and subject and a relationship between subject and module(module consists of several materials) Thanks.

            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