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. What is the best method

What is the best method

Scheduled Pinned Locked Moved ASP.NET
databasesharepointsecurityxmlquestion
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

    Hello I work on an intranet site management fees. management part of review tired me, I chose to work with Excel for simplicity That's what I want to do: I have a listbox containing the modules , for a list of students registered in a module, the responsable for this must complete an authentication form. I want that after authenticating the excel file containing the student opens (I do not know if this is the right method, you comments are welcome) to export data from sqlserver to excel I used this code:

    cn.Open();
    SqlDataAdapter da = new SqlDataAdapter(@"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

    ", cn);
    DataTable dt = new DataTable();
    da.Fill(dt);
    cn.Close();

       Response.Clear();
       Response.ContentType = "application/vnd.ms-excel";
       string sep = "";
       foreach (DataColumn dc in dt.Columns)
       {
              Response.Write(sep + dc.ColumnName);
              sep = "\\t";
       }
       Response.Write("\\n");
    
       int i;
       foreach (DataRow dr in dt.Rows)
       {
              sep = "";
              for (i = 0; i < dt.Columns.Count; i++)
              {
                     Response.Write(sep + dr\[i\].ToString());
                     sep = "\\t";
              }
              Response.Write("\\n");
       }
    

    }

    }

    this code works with sql queries simple but with my query i had an em

    V 1 Reply Last reply
    0
    • A amina89

      Hello I work on an intranet site management fees. management part of review tired me, I chose to work with Excel for simplicity That's what I want to do: I have a listbox containing the modules , for a list of students registered in a module, the responsable for this must complete an authentication form. I want that after authenticating the excel file containing the student opens (I do not know if this is the right method, you comments are welcome) to export data from sqlserver to excel I used this code:

      cn.Open();
      SqlDataAdapter da = new SqlDataAdapter(@"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

      ", cn);
      DataTable dt = new DataTable();
      da.Fill(dt);
      cn.Close();

         Response.Clear();
         Response.ContentType = "application/vnd.ms-excel";
         string sep = "";
         foreach (DataColumn dc in dt.Columns)
         {
                Response.Write(sep + dc.ColumnName);
                sep = "\\t";
         }
         Response.Write("\\n");
      
         int i;
         foreach (DataRow dr in dt.Rows)
         {
                sep = "";
                for (i = 0; i < dt.Columns.Count; i++)
                {
                       Response.Write(sep + dr\[i\].ToString());
                       sep = "\\t";
                }
                Response.Write("\\n");
         }
      

      }

      }

      this code works with sql queries simple but with my query i had an em

      V Offline
      V Offline
      Viral Upadhyay
      wrote on last edited by
      #2

      I think you should debug your code first and see what you get in DataTable. if it is working fine then you can think of other option. :rose:

      Viral My Site
      Save Our Tigers

      A 1 Reply Last reply
      0
      • V Viral Upadhyay

        I think you should debug your code first and see what you get in DataTable. if it is working fine then you can think of other option. :rose:

        Viral My Site
        Save Our Tigers

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

        Thank you very much Viral Upadhyay, :) My code work I, it gives me a dialog box to open or register the excel file .but it is in the server or the client? if the file is in the server how to send the client by simple download or??? Thanks

        V 1 Reply Last reply
        0
        • A amina89

          Thank you very much Viral Upadhyay, :) My code work I, it gives me a dialog box to open or register the excel file .but it is in the server or the client? if the file is in the server how to send the client by simple download or??? Thanks

          V Offline
          V Offline
          Viral Upadhyay
          wrote on last edited by
          #4

          Actually i am taking about is your datatable which fetch data from database has record or not? but its look like you have done every thing right. By the way the dialog box you see is for download or open file from server to client.

          Viral My Site
          Save Our Tigers

          A 1 Reply Last reply
          0
          • V Viral Upadhyay

            Actually i am taking about is your datatable which fetch data from database has record or not? but its look like you have done every thing right. By the way the dialog box you see is for download or open file from server to client.

            Viral My Site
            Save Our Tigers

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

            Thank you very much Viral Upadhyay:) my english is bad i undrstand that the dialog box will be open in the pc of teachers and they will record notes and then send files to servers or directly to the database. thank you.

            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