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. Database & SysAdmin
  3. Database
  4. checking the fieldname in the table

checking the fieldname in the table

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintutorialquestion
7 Posts 4 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.
  • D Offline
    D Offline
    Dhyanga
    wrote on last edited by
    #1

    Hi, I have one table in excel and I would like to send the data from excel to sql server. The excel data are not fixed. The columns name varies depending on the user. so let say if i have one table in excel named StuentInfo. Then the columns in that table may includes the field like ID, studentID,student ID like that along with other detail info. For example table field may be studentID studentName studentDetails or ID studentName studentDetails or ID student_Id studentName studentDetails so since ID can be studentID,ID or student_Id, i would need to check which of them the table contains. Is it anyway I can check the columnName in the table ? In one of the table, there are two Ids viz ID and student_Id. In that case, we are considering student_Id as the correct one? Is there any query expression to check the column name of the table?

    suchita

    P M S 3 Replies Last reply
    0
    • D Dhyanga

      Hi, I have one table in excel and I would like to send the data from excel to sql server. The excel data are not fixed. The columns name varies depending on the user. so let say if i have one table in excel named StuentInfo. Then the columns in that table may includes the field like ID, studentID,student ID like that along with other detail info. For example table field may be studentID studentName studentDetails or ID studentName studentDetails or ID student_Id studentName studentDetails so since ID can be studentID,ID or student_Id, i would need to check which of them the table contains. Is it anyway I can check the columnName in the table ? In one of the table, there are two Ids viz ID and student_Id. In that case, we are considering student_Id as the correct one? Is there any query expression to check the column name of the table?

      suchita

      P Online
      P Online
      PIEBALDconsult
      wrote on last edited by
      #2

      I'd use an EnumTransmogrifier<T> [^]. Make an enum like:

      enum ColumnName
      {
      [System.ComponentModel.DescriptionAttribute("ID")]
      [System.ComponentModel.DescriptionAttribute("student_Id")]
      studentID

      etc.
      studentName

      etc.
      studentDetails
      }

      Then, when you open a file, parse the actual column names to a logical column names and cache the indices. Slick as snot.

      1 Reply Last reply
      0
      • D Dhyanga

        Hi, I have one table in excel and I would like to send the data from excel to sql server. The excel data are not fixed. The columns name varies depending on the user. so let say if i have one table in excel named StuentInfo. Then the columns in that table may includes the field like ID, studentID,student ID like that along with other detail info. For example table field may be studentID studentName studentDetails or ID studentName studentDetails or ID student_Id studentName studentDetails so since ID can be studentID,ID or student_Id, i would need to check which of them the table contains. Is it anyway I can check the columnName in the table ? In one of the table, there are two Ids viz ID and student_Id. In that case, we are considering student_Id as the correct one? Is there any query expression to check the column name of the table?

        suchita

        M Offline
        M Offline
        Mohamad Kaifi
        wrote on last edited by
        #3

        Hi Suchita, You can get column names in SQl Server using the following query: --This will give you all the column names in the customer table Select COLUMN_NAME From .INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME = 'Customer' Hope this solves your problem. Thanks, Kaifee

        P D 2 Replies Last reply
        0
        • M Mohamad Kaifi

          Hi Suchita, You can get column names in SQl Server using the following query: --This will give you all the column names in the customer table Select COLUMN_NAME From .INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME = 'Customer' Hope this solves your problem. Thanks, Kaifee

          P Online
          P Online
          PIEBALDconsult
          wrote on last edited by
          #4

          Will that work with Excel? Using a DataReader is simpler and works with any ADO.net-compatible database.

          1 Reply Last reply
          0
          • D Dhyanga

            Hi, I have one table in excel and I would like to send the data from excel to sql server. The excel data are not fixed. The columns name varies depending on the user. so let say if i have one table in excel named StuentInfo. Then the columns in that table may includes the field like ID, studentID,student ID like that along with other detail info. For example table field may be studentID studentName studentDetails or ID studentName studentDetails or ID student_Id studentName studentDetails so since ID can be studentID,ID or student_Id, i would need to check which of them the table contains. Is it anyway I can check the columnName in the table ? In one of the table, there are two Ids viz ID and student_Id. In that case, we are considering student_Id as the correct one? Is there any query expression to check the column name of the table?

            suchita

            S Offline
            S Offline
            Simon_Whale
            wrote on last edited by
            #5

            Have you thought about using the openrowset functionality of SQL Server? and letting SQL check to see if the values in the spreadsheet are in the database? rather than Excel doing the work! MSDN: Openrowset[^]

            Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

            D 1 Reply Last reply
            0
            • M Mohamad Kaifi

              Hi Suchita, You can get column names in SQl Server using the following query: --This will give you all the column names in the customer table Select COLUMN_NAME From .INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME = 'Customer' Hope this solves your problem. Thanks, Kaifee

              D Offline
              D Offline
              Dhyanga
              wrote on last edited by
              #6

              Can I get the same output if I have an excel file ? Actually I want the data from the excel file and insert it into the sql server. Is there anyway I can get the same output with the excel file?

              suchita

              1 Reply Last reply
              0
              • S Simon_Whale

                Have you thought about using the openrowset functionality of SQL Server? and letting SQL check to see if the values in the spreadsheet are in the database? rather than Excel doing the work! MSDN: Openrowset[^]

                Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                D Offline
                D Offline
                Dhyanga
                wrote on last edited by
                #7

                Hi I don't have choice. My clients or users uploads their file in excel and from that excel file, i have to read the data and insert it into the sql server.

                suchita

                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