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. binding data to datagrid

binding data to datagrid

Scheduled Pinned Locked Moved ASP.NET
wpfwcfquestion
9 Posts 3 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.
  • H Offline
    H Offline
    h ma
    wrote on last edited by
    #1

    in windows apllication, i want to select table's data and show it in datagrid but i dont undertand how will i bind the data is there any way to use datagrd view manager or something like this???? m confused!!!:(

    $h@ma!|@

    T 1 Reply Last reply
    0
    • H h ma

      in windows apllication, i want to select table's data and show it in datagrid but i dont undertand how will i bind the data is there any way to use datagrd view manager or something like this???? m confused!!!:(

      $h@ma!|@

      T Offline
      T Offline
      Tirthadip
      wrote on last edited by
      #2

      execute SQL statement.....and fill a DataSet with your information if you use ACCESS as a database and VB.NET as your language then follow... Dim mySql AS String="SELECT * FROM myTable" //Suppose you have a DataAdaptor(da) And DataSet(ds) Dim ds As DataSet Dim da As OleDbDataAdapter da = New OleDbDataAdapter(mySql, myConnection) ds = New DataSet da.Fill(ds) //set DatSource of your datagrid to the dataset DataGrid1.DataSource=ds

      Tirtha Do not go where the path may lead, go instead where there is no path and leave a trail. Author: Ralph Waldo Emerson (1803-82), American writer, philosopher, poet, essayist

      H 1 Reply Last reply
      0
      • T Tirthadip

        execute SQL statement.....and fill a DataSet with your information if you use ACCESS as a database and VB.NET as your language then follow... Dim mySql AS String="SELECT * FROM myTable" //Suppose you have a DataAdaptor(da) And DataSet(ds) Dim ds As DataSet Dim da As OleDbDataAdapter da = New OleDbDataAdapter(mySql, myConnection) ds = New DataSet da.Fill(ds) //set DatSource of your datagrid to the dataset DataGrid1.DataSource=ds

        Tirtha Do not go where the path may lead, go instead where there is no path and leave a trail. Author: Ralph Waldo Emerson (1803-82), American writer, philosopher, poet, essayist

        H Offline
        H Offline
        h ma
        wrote on last edited by
        #3

        well! isnt there any need to use data reader?? well my code is //connection as conn strQuery = " SELECT * FROM table"; SqlCommand com1 = new SqlCommand(strQuery, conn); DataSet ds=new DataSet(); SqlDataAdapter da=new SqlDataAdapter(); SqlDataReader dr = com1.ExecuteReader(); if (dr.Read()) { da.Fill(ds,"table"); } its not working i mean data is not displaying in the grid..and the exception that is shown is "The SelectCommand property has not been initialized before calling 'Fill'."

        $h@ma!|@

        T 1 Reply Last reply
        0
        • H h ma

          well! isnt there any need to use data reader?? well my code is //connection as conn strQuery = " SELECT * FROM table"; SqlCommand com1 = new SqlCommand(strQuery, conn); DataSet ds=new DataSet(); SqlDataAdapter da=new SqlDataAdapter(); SqlDataReader dr = com1.ExecuteReader(); if (dr.Read()) { da.Fill(ds,"table"); } its not working i mean data is not displaying in the grid..and the exception that is shown is "The SelectCommand property has not been initialized before calling 'Fill'."

          $h@ma!|@

          T Offline
          T Offline
          Tirthadip
          wrote on last edited by
          #4

          why are u using datareader and dataset simultaneously??? follow this... '1. Create a connection Dim myConnection as New SqlConnection( ConfigurationSettings.AppSettings("connectionString")) '2. Create the command object, passing in the SQL string Const strSQL as String = "SELECT * FROM myTable" Dim myCommand as New SqlCommand(strSQL, myConnection) 'Set the datagrid's datasource to the datareader and databind myConnection.Open() DataGrid1.DataSource = myCommand.ExecuteReader( CommandBehavior.CloseConnection) DataGrid1.DataBind() but keep in mind A datareader is a read-only object. If you need to edit and update changes you need to use a dataset.

          Tirtha Do not go where the path may lead, go instead where there is no path and leave a trail. Author: Ralph Waldo Emerson (1803-82), American writer, philosopher, poet, essayist

          H 1 Reply Last reply
          0
          • T Tirthadip

            why are u using datareader and dataset simultaneously??? follow this... '1. Create a connection Dim myConnection as New SqlConnection( ConfigurationSettings.AppSettings("connectionString")) '2. Create the command object, passing in the SQL string Const strSQL as String = "SELECT * FROM myTable" Dim myCommand as New SqlCommand(strSQL, myConnection) 'Set the datagrid's datasource to the datareader and databind myConnection.Open() DataGrid1.DataSource = myCommand.ExecuteReader( CommandBehavior.CloseConnection) DataGrid1.DataBind() but keep in mind A datareader is a read-only object. If you need to edit and update changes you need to use a dataset.

            Tirtha Do not go where the path may lead, go instead where there is no path and leave a trail. Author: Ralph Waldo Emerson (1803-82), American writer, philosopher, poet, essayist

            H Offline
            H Offline
            h ma
            wrote on last edited by
            #5

            hmmmm but as i told i m working in windows application and it doesnt support databind option is there any replacement or any directives/namespaces to include? and what if i want to update records using dataset?

            $h@ma!|@

            H 1 Reply Last reply
            0
            • H h ma

              hmmmm but as i told i m working in windows application and it doesnt support databind option is there any replacement or any directives/namespaces to include? and what if i want to update records using dataset?

              $h@ma!|@

              H Offline
              H Offline
              h ma
              wrote on last edited by
              #6

              waiting for ur answer:confused:

              $h@ma!|@

              T 1 Reply Last reply
              0
              • H h ma

                waiting for ur answer:confused:

                $h@ma!|@

                T Offline
                T Offline
                Tirthadip
                wrote on last edited by
                #7

                sorry shamaila I have forgotten that yours a windows application... then you have to make a datatable with that datareader and bind it to the datagrid.... i dont see any other option for you..

                Tirtha Do not go where the path may lead, go instead where there is no path and leave a trail. Author: Ralph Waldo Emerson (1803-82), American writer, philosopher, poet, essayist

                V 1 Reply Last reply
                0
                • T Tirthadip

                  sorry shamaila I have forgotten that yours a windows application... then you have to make a datatable with that datareader and bind it to the datagrid.... i dont see any other option for you..

                  Tirtha Do not go where the path may lead, go instead where there is no path and leave a trail. Author: Ralph Waldo Emerson (1803-82), American writer, philosopher, poet, essayist

                  V Offline
                  V Offline
                  valerian precop
                  wrote on last edited by
                  #8

                  Here is a databind for a grid view in windows application: //... SqlConnection conn = new SqlConnection(connectionString); conn.Open(); string strQuery = "SELECT * FROM tableTest"; SqlCommand com1 = new SqlCommand(strQuery, conn); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(com1); da.Fill(ds, "table"); dataGridView1.DataSource = ds; dataGridView1.DataMember = "table"; //... I hope it works...it worked when I've tested it :)

                  H 1 Reply Last reply
                  0
                  • V valerian precop

                    Here is a databind for a grid view in windows application: //... SqlConnection conn = new SqlConnection(connectionString); conn.Open(); string strQuery = "SELECT * FROM tableTest"; SqlCommand com1 = new SqlCommand(strQuery, conn); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(com1); da.Fill(ds, "table"); dataGridView1.DataSource = ds; dataGridView1.DataMember = "table"; //... I hope it works...it worked when I've tested it :)

                    H Offline
                    H Offline
                    h ma
                    wrote on last edited by
                    #9

                    thx alot it really worked :-D so nice of u...and m feeling sorry as i found ur reply too late

                    $h@ma!|@

                    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