Naive Database Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith Rebello

    Naive Database Question

    I use VB.Net in VS2005 and rarely use databases.



    I have a database to which I open a connection in my application (using
    ADO). Once I have the connection, I loop through each table in the database
    using a command string ("Select * from .) and a DataAdapter to populate a
    DataSet. I then close the connection.



    If I understand this correctly, I now have a copy of the database in memory.
    I cannot seem to find a way to query this DataSet to limit the rows and
    columns that I want to see in my DataGridView. Using
    DataSet.Tables. Select( , ) I can limit the number of rows based on a
    criterion, but cannot seem to limit the number of columns.



    Am I trying to do something that is not possible? If it is possible, please
    offer some suggestions. Or, do I have to re-open the connection and
    re-query the original database?



    Keith Rebello.


  • Steve Gerrard

    #2
    Re: Naive Database Question

    Keith Rebello wrote:
    I use VB.Net in VS2005 and rarely use databases.
    >
    I have a database to which I open a connection in my application
    (using ADO). Once I have the connection, I loop through each table
    in the database using a command string ("Select * from .) and a
    DataAdapter to populate a DataSet. I then close the connection.
    >
    If I understand this correctly, I now have a copy of the database in
    memory. I cannot seem to find a way to query this DataSet to limit
    the rows and columns that I want to see in my DataGridView. Using
    DataSet.Tables. Select( , ) I can limit the number of rows based on a
    criterion, but cannot seem to limit the number of columns.
    >
    Am I trying to do something that is not possible? If it is possible,
    please offer some suggestions. Or, do I have to re-open the
    connection and re-query the original database?
    >
    Normally you would just set the datagridview to display the columns of interest,
    regardless of how many columns are actually in the datarows you are using as a
    datasource.


    Comment

    • Patrice

      #3
      Re: Naive Database Question

      Windows or web application ? In both case you can explicitely define which
      columns you want to see (see the Columns collection).

      Anyway, this is really not how a DataSet should be used. See this rather as
      a "cache" rather than a "copy". The idea is rather to keep around the rows
      the user needs at a given time and to move them back and forth in the
      dataset or to the db as needed, note to copy the whole db...

      --
      Patrice

      "Keith Rebello" <krebello@coref undamentals.com a écrit dans le message de
      groupe de discussion : YMAYj.89$7k1.66 @newsfe24.lga.. .
      I use VB.Net in VS2005 and rarely use databases.
      >
      >
      >
      I have a database to which I open a connection in my application (using
      ADO). Once I have the connection, I loop through each table in the
      database using a command string ("Select * from .) and a DataAdapter to
      populate a DataSet. I then close the connection.
      >
      >
      >
      If I understand this correctly, I now have a copy of the database in
      memory. I cannot seem to find a way to query this DataSet to limit the
      rows and columns that I want to see in my DataGridView. Using
      DataSet.Tables. Select( , ) I can limit the number of rows based on a
      criterion, but cannot seem to limit the number of columns.
      >
      >
      >
      Am I trying to do something that is not possible? If it is possible,
      please offer some suggestions. Or, do I have to re-open the connection
      and re-query the original database?
      >
      >
      >
      Keith Rebello.
      >
      >

      Comment

      • Keith Rebello

        #4
        Re: Naive Database Question

        Thanks Steve.

        The problem I have is that the DataGridView will have a different number of
        columns and column header names dependent on which table in the dataset I
        wish to query. That is why it would be nice to be able to query the DataSet
        on a table-by-table basis and have the DataGridView display only pertinent
        information.

        Keith Rebello

        "Steve Gerrard" <mynamehere@com cast.netwrote in message
        news:OIudnbhhmZ xBdK_VnZ2dnUVZ_ r6rnZ2d@comcast .com...
        Keith Rebello wrote:
        >I use VB.Net in VS2005 and rarely use databases.
        >>
        >I have a database to which I open a connection in my application
        >(using ADO). Once I have the connection, I loop through each table
        >in the database using a command string ("Select * from .) and a
        >DataAdapter to populate a DataSet. I then close the connection.
        >>
        >If I understand this correctly, I now have a copy of the database in
        >memory. I cannot seem to find a way to query this DataSet to limit
        >the rows and columns that I want to see in my DataGridView. Using
        >DataSet.Tables .Select( , ) I can limit the number of rows based on a
        >criterion, but cannot seem to limit the number of columns.
        >>
        >Am I trying to do something that is not possible? If it is possible,
        >please offer some suggestions. Or, do I have to re-open the
        >connection and re-query the original database?
        >>
        >
        Normally you would just set the datagridview to display the columns of
        interest, regardless of how many columns are actually in the datarows you
        are using as a datasource.
        >

        Comment

        • Keith Rebello

          #5
          Re: Naive Database Question

          Thanks Patrice. From your post, it makes sense for me to re-connect to and
          re-query the database.
          For completeness, it is a Windows application and the database is small in
          size and is only a small component of the application.

          Keith Rebello.


          "Patrice" <http://www.chez.com/scribe/wrote in message
          news:F4546303-FD44-43E4-8690-7DF7768FF664@mi crosoft.com...
          Windows or web application ? In both case you can explicitely define which
          columns you want to see (see the Columns collection).
          >
          Anyway, this is really not how a DataSet should be used. See this rather
          as a "cache" rather than a "copy". The idea is rather to keep around the
          rows the user needs at a given time and to move them back and forth in the
          dataset or to the db as needed, note to copy the whole db...
          >
          --
          Patrice
          >
          "Keith Rebello" <krebello@coref undamentals.com a écrit dans le message de
          groupe de discussion : YMAYj.89$7k1.66 @newsfe24.lga.. .
          >I use VB.Net in VS2005 and rarely use databases.
          >>
          >>
          >>
          >I have a database to which I open a connection in my application (using
          >ADO). Once I have the connection, I loop through each table in the
          >database using a command string ("Select * from .) and a DataAdapter to
          >populate a DataSet. I then close the connection.
          >>
          >>
          >>
          >If I understand this correctly, I now have a copy of the database in
          >memory. I cannot seem to find a way to query this DataSet to limit the
          >rows and columns that I want to see in my DataGridView. Using
          >DataSet.Tables .Select( , ) I can limit the number of rows based on a
          >criterion, but cannot seem to limit the number of columns.
          >>
          >>
          >>
          >Am I trying to do something that is not possible? If it is possible,
          >please offer some suggestions. Or, do I have to re-open the connection
          >and re-query the original database?
          >>
          >>
          >>
          >Keith Rebello.
          >>
          >>
          >

          Comment

          • Steve Gerrard

            #6
            Re: Naive Database Question

            Keith Rebello wrote:
            >
            The problem I have is that the DataGridView will have a different
            number of columns and column header names dependent on which table in
            the dataset I wish to query. That is why it would be nice to be able
            to query the DataSet on a table-by-table basis and have the
            DataGridView display only pertinent information.
            >
            If you like the auto-generated columns, it should not be hard to loop through
            the columns collection after binding a different datasource, and setting visible
            to false for the columns you don't want to see - or removing them, for that
            matter.

            Or you can take control outright, and set AutoGenerateCol umns to false. Then
            when you change datasource, clear the columns and setup the ones you want. Don't
            be fooled into thinking that AutoGenerateCol umns does anything different: it
            just finds the table's column collection, and loops through, setting up a grid
            column for each table column. Doing it yourself gives you a much finer level of
            control on a number of properties, such as the header text and format, as well
            as control over which columns to show.



            Comment

            Working...