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. General Programming
  3. Visual Basic
  4. Linking a .Net 2003 DataGrid with a query

Linking a .Net 2003 DataGrid with a query

Scheduled Pinned Locked Moved Visual Basic
databasequestioncsharp
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.
  • F Offline
    F Offline
    ford86
    wrote on last edited by
    #1

    I want my dataGrid's DataSource to be a Query from my MSAccess Database, but I can only put a DataTable from a DataSet as the DataSource. Is there an other way that the DataSource can be linked with my Query? (...too many "data" in this question...) Thanks!

    D N 2 Replies Last reply
    0
    • F ford86

      I want my dataGrid's DataSource to be a Query from my MSAccess Database, but I can only put a DataTable from a DataSet as the DataSource. Is there an other way that the DataSource can be linked with my Query? (...too many "data" in this question...) Thanks!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You can put the DataSet as a DataSource, then the DataMember property should be the name of a table in the DataSet.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      F 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You can put the DataSet as a DataSource, then the DataMember property should be the name of a table in the DataSet.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        F Offline
        F Offline
        ford86
        wrote on last edited by
        #3

        That's what I'm doing right now, but I don't want the DataMember to be a table but rather a query. Is there a way to to this? The reason I want to do that is because I need to do operations in the grid, but I really don't know how. That's why I did a Query in MSAcces, but I can't use it as a dataSource for the grid.

        P D 2 Replies Last reply
        0
        • F ford86

          That's what I'm doing right now, but I don't want the DataMember to be a table but rather a query. Is there a way to to this? The reason I want to do that is because I need to do operations in the grid, but I really don't know how. That's why I did a Query in MSAcces, but I can't use it as a dataSource for the grid.

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          You should probably look for a good book on interacting with VB and databases.

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer

          1 Reply Last reply
          0
          • F ford86

            That's what I'm doing right now, but I don't want the DataMember to be a table but rather a query. Is there a way to to this? The reason I want to do that is because I need to do operations in the grid, but I really don't know how. That's why I did a Query in MSAcces, but I can't use it as a dataSource for the grid.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            ford86 wrote:

            That's what I'm doing right now, but I don't want the DataMember to be a table but rather a query. Is there a way to to this?

            No, there isn't. Any query is going to return the results in either a DataSet (multiple tables) or a DataTable object. If your query is returning data from a single table, you can keep it in a DataTable and bind the DataGridView to that.

            ford86 wrote:

            That's why I did a Query in MSAcces, but I can't use it as a dataSource for the grid.

            Of course you can!! The exact same query is going to return results in a DataTable or DataSet. Seriously, you need to pickup a book on VB.NET and/or ADO.NET and work through it.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            1 Reply Last reply
            0
            • F ford86

              I want my dataGrid's DataSource to be a Query from my MSAccess Database, but I can only put a DataTable from a DataSet as the DataSource. Is there an other way that the DataSource can be linked with my Query? (...too many "data" in this question...) Thanks!

              N Offline
              N Offline
              Naji El Kotob
              wrote on last edited by
              #6

              Hi, You can assign a join query to DataAdapter, fill the DataSet, Create a DataView and link it to the table, apply filter on the RowFilter Property of DV Private DS As New DataSet Private DA As SqlClient.SqlDataAdapter Private DV As DataView ... Dim ConnString As String = "Data Source...." DA = New SqlClient.SqlDataAdapter("SELECT ... FROM Table1 INNER JOIN Table2 ON ...", ConnString) DA.Fill(DS, "TwoTables") DV = New DataView(DS.Tables("TwoTables")) dg.DataSource = DV ... DV.RowFilter = "ID = 2" ' > < <> ... Note: Update here has some restrictions! hope this helps :)

              NajiCo http://www.InsideVB.NET[^] It's nice 2b important, but it's more important 2b nice...

              P 1 Reply Last reply
              0
              • N Naji El Kotob

                Hi, You can assign a join query to DataAdapter, fill the DataSet, Create a DataView and link it to the table, apply filter on the RowFilter Property of DV Private DS As New DataSet Private DA As SqlClient.SqlDataAdapter Private DV As DataView ... Dim ConnString As String = "Data Source...." DA = New SqlClient.SqlDataAdapter("SELECT ... FROM Table1 INNER JOIN Table2 ON ...", ConnString) DA.Fill(DS, "TwoTables") DV = New DataView(DS.Tables("TwoTables")) dg.DataSource = DV ... DV.RowFilter = "ID = 2" ' > < <> ... Note: Update here has some restrictions! hope this helps :)

                NajiCo http://www.InsideVB.NET[^] It's nice 2b important, but it's more important 2b nice...

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #7

                Not sure if you can use SqlDataAdapter on Access databases. That is for SQL Server....

                "The clue train passed his station without stopping." - John Simmons / outlaw programmer

                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