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. COLUMN WISE DISPLAYING TWO QUERIE VALUE FROM DATASET TO GRIDVIEW

COLUMN WISE DISPLAYING TWO QUERIE VALUE FROM DATASET TO GRIDVIEW

Scheduled Pinned Locked Moved ASP.NET
databasecsharpsql-serversysadmin
9 Posts 5 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.
  • K Offline
    K Offline
    Karan_TN
    wrote on last edited by
    #1

    hai, currently i m using vb.net 2005 (framework 2.0) and sql server 2000. here i have two query where i bind those values to gridview. i need the values in column wise. for example... sql1=select studentname from tab_student sql2=select employeename from tab_employee The result of the above queries should be combined in a single gridview COLUMN WISE (note : no relationship between two tables) waiting for the reply - KARAN

    S A T 3 Replies Last reply
    0
    • K Karan_TN

      hai, currently i m using vb.net 2005 (framework 2.0) and sql server 2000. here i have two query where i bind those values to gridview. i need the values in column wise. for example... sql1=select studentname from tab_student sql2=select employeename from tab_employee The result of the above queries should be combined in a single gridview COLUMN WISE (note : no relationship between two tables) waiting for the reply - KARAN

      S Offline
      S Offline
      sudhanvag
      wrote on last edited by
      #2

      Hi karan, I dont know why you want to show it like that, but you can loop through two tables, i mean having two loops one inside the other (Note: Outer for loop should be for max row count table) and add the data in to a new table. Then bind the new table to the grid. I have not implemented this, but i am sure this should work. Try. Cheers, Sudhanva.

      1 Reply Last reply
      0
      • K Karan_TN

        hai, currently i m using vb.net 2005 (framework 2.0) and sql server 2000. here i have two query where i bind those values to gridview. i need the values in column wise. for example... sql1=select studentname from tab_student sql2=select employeename from tab_employee The result of the above queries should be combined in a single gridview COLUMN WISE (note : no relationship between two tables) waiting for the reply - KARAN

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

        Why not use a union?

        select studentname as [Name] from tab_student
        union all
        select employeename as [Name] from tab_employee

        then you only have 1 lot of data to bind, and you can put an order by on the query too.

        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

        A K 2 Replies Last reply
        0
        • A Ashfield

          Why not use a union?

          select studentname as [Name] from tab_student
          union all
          select employeename as [Name] from tab_employee

          then you only have 1 lot of data to bind, and you can put an order by on the query too.

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4

          Hey Bob, Congrats

          cheers, Abhijit CodeProject.Com MVP

          A 1 Reply Last reply
          0
          • K Karan_TN

            hai, currently i m using vb.net 2005 (framework 2.0) and sql server 2000. here i have two query where i bind those values to gridview. i need the values in column wise. for example... sql1=select studentname from tab_student sql2=select employeename from tab_employee The result of the above queries should be combined in a single gridview COLUMN WISE (note : no relationship between two tables) waiting for the reply - KARAN

            T Offline
            T Offline
            ToddHileHoffer
            wrote on last edited by
            #5

            You could combine your results in SQL. or You could add a template column to your gridview and set the values in the OnRowDatabound.

            I didn't get any requirements for the signature

            S 1 Reply Last reply
            0
            • A Abhijit Jana

              Hey Bob, Congrats

              cheers, Abhijit CodeProject.Com MVP

              A Offline
              A Offline
              Ashfield
              wrote on last edited by
              #6

              And you also. Its a good feeling to get that diamond :)

              Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

              1 Reply Last reply
              0
              • A Ashfield

                Why not use a union?

                select studentname as [Name] from tab_student
                union all
                select employeename as [Name] from tab_employee

                then you only have 1 lot of data to bind, and you can put an order by on the query too.

                Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                K Offline
                K Offline
                Karan_TN
                wrote on last edited by
                #7

                will this result display in two different COLUMNS?

                A 1 Reply Last reply
                0
                • K Karan_TN

                  will this result display in two different COLUMNS?

                  A Offline
                  A Offline
                  Ashfield
                  wrote on last edited by
                  #8

                  No, you will get 1 column called Name which contains all the studentname values plus all the employeename values - thats what unions are about!

                  Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                  1 Reply Last reply
                  0
                  • T ToddHileHoffer

                    You could combine your results in SQL. or You could add a template column to your gridview and set the values in the OnRowDatabound.

                    I didn't get any requirements for the signature

                    S Offline
                    S Offline
                    sudhanvag
                    wrote on last edited by
                    #9
                        DataTable dt1 = new DataTable("student");
                        dt1.Columns.Add("Name", typeof(string));
                        dt1.Rows.Add("a"); dt1.Rows.Add("b"); dt1.Rows.Add("c");
                        
                    
                        DataTable dt2 = new DataTable("employee");
                        dt2.Columns.Add("Name", typeof(string));
                        dt2.Rows.Add("x"); dt2.Rows.Add("y"); dt2.Rows.Add("z");
                         
                    
                        DataTable dt3 = new DataTable("student\_employee");
                        dt3.Columns.Add("StudentName", typeof(string));
                        dt3.Columns.Add("EmployeeName", typeof(string));
                         
                      
                        //further you can add an IF condition to check the max dt.row.count here
                        for (int i = 0; i < dt1.Rows.Count; i++ )
                        {
                            for (int j = 0; j < dt2.Rows.Count; j++)
                            {
                                dt3.Rows.Add(dt1.Rows\[i\]\["Name"\].ToString(), dt2.Rows\[i\]\["Name"\].ToString());
                                break;
                            }
                        }
                    
                        //bind the dt3 with gridview here
                    

                    Cheers, Sudhanva

                    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