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. Datatables

Datatables

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
17 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.
  • C Christian Graus

    chohanpk wrote:

    SqlDataAdapter adp2 = new SqlDataAdapter("select * from tblcheck", con); adp2.Fill(ds, "tblcheck"); GridView1.DataSource = ds; GridView1.DataBind();

    This is looking for a table in your database, creating one in local memory, with nothing in it, is not going to do anything.  Even if you were examining the table you created ( in memory, not in you DB ), it would still be empty. What are you hoping to achieve here ?

    Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

    C Offline
    C Offline
    chohanpk
    wrote on last edited by
    #8

    here is code: DataTable dt = new DataTable("tblcheck"); DataColumn dc1 = new DataColumn("col1", typeof(int)); dt.Columns.Add(dc1); DataColumn dc2 = new DataColumn("col2", typeof(int)); dt.Columns.Add(dc2); DataSet ds = new DataSet(); ds.Tables.Add(dt); DataRow dr1 = dt.NewRow(); dr1["col1"] = 1; dr1["col2"] = 2; dt.Rows.Add(dr1); //SqlDataAdapter adp2 = new SqlDataAdapter("select col1 from dt", con); //adp2.Fill(ds, "dt"); GridView1.DataSource = ds; GridView1.DataBind(); if i dont nclude these rows, "SqlDataAdapter adp2 = new SqlDataAdapter("select col1 from dt", con); adp2.Fill(ds, "dt");" then it shows values. but with these dataadapter code it gives error.i want to use dataadpater to fill the dataset.what will be the solution?

    Chohan

    C 1 Reply Last reply
    0
    • C chohanpk

      here is code: DataTable dt = new DataTable("tblcheck"); DataColumn dc1 = new DataColumn("col1", typeof(int)); dt.Columns.Add(dc1); DataColumn dc2 = new DataColumn("col2", typeof(int)); dt.Columns.Add(dc2); DataSet ds = new DataSet(); ds.Tables.Add(dt); DataRow dr1 = dt.NewRow(); dr1["col1"] = 1; dr1["col2"] = 2; dt.Rows.Add(dr1); //SqlDataAdapter adp2 = new SqlDataAdapter("select col1 from dt", con); //adp2.Fill(ds, "dt"); GridView1.DataSource = ds; GridView1.DataBind(); if i dont nclude these rows, "SqlDataAdapter adp2 = new SqlDataAdapter("select col1 from dt", con); adp2.Fill(ds, "dt");" then it shows values. but with these dataadapter code it gives error.i want to use dataadpater to fill the dataset.what will be the solution?

      Chohan

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

      chohanpk wrote:

      .i want to use dataadpater to fill the dataset

      OK, then you need to point the dataadapter to a table that exists

      chohanpk wrote:

      select col1 from dt

      OK, that plain won't work.  In your SQL, you're pointing to objects in your database, not local variables.

      Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

      C 1 Reply Last reply
      0
      • C Christian Graus

        chohanpk wrote:

        .i want to use dataadpater to fill the dataset

        OK, then you need to point the dataadapter to a table that exists

        chohanpk wrote:

        select col1 from dt

        OK, that plain won't work.  In your SQL, you're pointing to objects in your database, not local variables.

        Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

        C Offline
        C Offline
        chohanpk
        wrote on last edited by
        #10

        tel me how can i do this? wht ll be the code?

        Chohan

        C 1 Reply Last reply
        0
        • C chohanpk

          tel me how can i do this? wht ll be the code?

          Chohan

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

          What you're trying to do, makes no sense.  What do you want to achieve ? Are you hoping to create a table in the DB ? Are you hoping to create a local table and use SQL on it ? You can specify a dataview, which operates SQL on a datatable, at least, I think you can.  why don't you just create a table in your database ?

          Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

          C 1 Reply Last reply
          0
          • C Christian Graus

            What you're trying to do, makes no sense.  What do you want to achieve ? Are you hoping to create a table in the DB ? Are you hoping to create a local table and use SQL on it ? You can specify a dataview, which operates SQL on a datatable, at least, I think you can.  why don't you just create a table in your database ?

            Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

            C Offline
            C Offline
            chohanpk
            wrote on last edited by
            #12

            i ve to do it with dataview.but i want to know how i can add it to db n then display through dataadapter.

            Chohan

            C 1 Reply Last reply
            0
            • C chohanpk

              i ve to do it with dataview.but i want to know how i can add it to db n then display through dataadapter.

              Chohan

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

              Well, wait a minute.  You don't want to write code that adds tables at random, do you ? you need to write the SQL to create the table, and execute it, through a connection, probably calling ExecuteNonQuery, as you want nothing back.  Then you need to run some inserts, if you want some data to select from.

              Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

              C 1 Reply Last reply
              0
              • C Christian Graus

                Well, wait a minute.  You don't want to write code that adds tables at random, do you ? you need to write the SQL to create the table, and execute it, through a connection, probably calling ExecuteNonQuery, as you want nothing back.  Then you need to run some inserts, if you want some data to select from.

                Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                C Offline
                C Offline
                chohanpk
                wrote on last edited by
                #14

                yeah.i want to add tables,insert columns ,rows and then display data of that tables.

                Chohan

                C 1 Reply Last reply
                0
                • C chohanpk

                  yeah.i want to add tables,insert columns ,rows and then display data of that tables.

                  Chohan

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

                  Why would you want to write a program that keeps adding tables to your database ? What for ?

                  Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                  C 1 Reply Last reply
                  0
                  • C Christian Graus

                    Why would you want to write a program that keeps adding tables to your database ? What for ?

                    Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                    C Offline
                    C Offline
                    chohanpk
                    wrote on last edited by
                    #16

                    now for learning purpose

                    Chohan

                    C 1 Reply Last reply
                    0
                    • C chohanpk

                      now for learning purpose

                      Chohan

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

                      OK, what you've hopefully learned is, create your tables in SQL, then query them using SQL in your C# code.

                      Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                      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