Results 1 to 9 of 9

Thread: datagrids (newbie question)

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    datagrids (newbie question)

    I am having a total brain fart with this...

    I have a form with 22 datagrid controls on it, they are populated from an Access database. I am wanting to read the data from the datagrid controls, the access database provides base data that the user may want to modify, but I can't for the life of me think how to do it. I know in VB6B you could set up a control array, but can this be done in .net 2003?

    ...Update have read through a few posts on control arrays and am still a little confused any help would be appreciated.

    regards,

    Matt

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datagrids (newbie question)

    Even if control arrays existed in VB.NET, the fact that you have multiple controls doesn't necessitate the use of a control array. Simply refer to each control individually. Create a bunch of DataAdapters and retrieve all the data into DataTables in a single DataSet. Bind the tables to the grids. The user makes there edits, then you call the Update method of each DataAdapter.
    Last edited by jmcilhinney; Apr 14th, 2007 at 06:52 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: datagrids (newbie question)

    I have bee following a book, so created a seperate dataadapter and dataset for each datagrid.

    If I bind the tables to the grids will this not update the original tables??? I want the user, the user also wants, to be able to have a sytandard set of data to work from each time the program is run.

    regards,

    Matt

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datagrids (newbie question)

    The whole premise of ADO.NET is that it is disconnected from the original data source. The general idea is this:

    You create a Connection object, which can be used to connect to your database.
    You create Command objects that contain an SQL statement (or statements) and a Connection, so they execute the SQL against the database referred to by the Connection.
    You create a DataAdapter that contains up to four Commands: one each to SELECT, DELETE, INSERT and UPDATE.
    You create DataTables to store the result set of a query. These are equivalent to database tables.
    You create DataSets to store multiple DataTables and the DataRelations between them, just as a database stores multiple tables and relationships. A DataSet is basically a local, in-memory database. It may, but does not have to have, the same schema as your main database.

    So, you create a DataAdapter and call its Fill method to populate a DataTable. The Fill method executes the SQL contained in the SelectCommand. You now have a local, disconnected copy of some of the data from your database. You then proceed to make whatever changes you see fit to that data. One of the most common ways to implement that is to bind the data to a grid. The grid provides a generally easy, logical way for the user to edit tabular data. The user may delete existing rows, insert new rows or edit existing rows. All these changes affect the local copy of the data only. Once you've made all your changes you now call the Update method of the same DataAdapter to save the contents of the DataTable to the database. This executes the SQL code in the DeleteCommand and/or InsertCommand and/or UpdateCommand.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: datagrids (newbie question)

    I think I follow this...

    Will give it a go later.

    regards,

    Matt

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: datagrids (newbie question)

    Right, I seem to have got this sorted now...

    One more question on Datagrids though:

    If I have a database file -

    Speed mpg Gear
    10 5 1
    10 6 2
    10 7 3
    10 8 4
    10 9 5
    20 2 1
    20 10 2
    20 11 3
    20 12 4
    20 13 5
    30 1 1
    ... ... ...
    50 42 5

    Is it possible to display this as shown below in a datagrid or not -
    **1 2 3 4 5
    10 5 6 7 8 9
    20 2 10 11 12 13
    ...

    regards,

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datagrids (newbie question)

    It's possible to show just about any data in just about any way you want, but you would have to massage it a bit first. You won't be able to simply perform a query on that data and display the result and have it look like that. You'll have to manipulate the data into that format yourself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: datagrids (newbie question)

    ok thanx...

    At least I now know it's possible.

    regards,

    Matt

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    54

    Re: datagrids (newbie question)

    Another question, is it possible reference a datagrid and get an idea of the number of columns and rows it uses??

    regards,

    Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width