Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

how can i insert Multiple values from datagrid to table in the database

Back to Forum: Tech Off
  • User profile image
    x.man

    hi all

    in the vb.net how can i insert the selected rows from datagridview to table in MSaccess database and that table is not the data source of the datagridview.  

    - that table well be same columns in the datagridview.  

    - i am tyro in the programing so i hop gave me the easy method. 

  • User profile image
    cheong

    I suppose you can use OleDbDataAdapter to Fill a Dataset, then get DataRow using RowCount and RowIndex provided, try add to the forementioned Dataset and perform update.

     

    Of course, even if you said the table structure is the same, there could be some deviation between structure of both table. If that's the cause, you'd need to call NewRow() to get the DataRow object matching your MSAccess table and loop through the cells of the rows.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    ScanIAm

    cheong said:

    I suppose you can use OleDbDataAdapter to Fill a Dataset, then get DataRow using RowCount and RowIndex provided, try add to the forementioned Dataset and perform update.

     

    Of course, even if you said the table structure is the same, there could be some deviation between structure of both table. If that's the cause, you'd need to call NewRow() to get the DataRow object matching your MSAccess table and loop through the cells of the rows.

    not to be a dick, but you shouldn't be allowing a datagrid to update your database.

     

    Process the changes in your business layer and let that layer do the updating.

  • User profile image
    x.man

    cheong said:

    I suppose you can use OleDbDataAdapter to Fill a Dataset, then get DataRow using RowCount and RowIndex provided, try add to the forementioned Dataset and perform update.

     

    Of course, even if you said the table structure is the same, there could be some deviation between structure of both table. If that's the cause, you'd need to call NewRow() to get the DataRow object matching your MSAccess table and loop through the cells of the rows.

    is there any example to learn from plz .

  • User profile image
    figuerres

    x.man said:
    cheong said:
    *snip*

    is there any example to learn from plz .

    I do not have an example but see if you can get started from here:

     

    the data grid has a source that is some kind of collection ... it may be a datatable or it may be a List of some type like List( of mydata)

    that collection can be stepped thru with a For loop or some other loop.

     

    write a loop that you can step thru with the visual studio debugger.

    then make your connection to the access database and find the code to add 1 row to that table.

    then put that code in the loop and use the data.

     

    after that you may also want to:

     

    use an access / ado.net "Transaction" to make sure that all the rows are saved if it works or you do a "Rollback" if the loop crashes with an error.

     

    add things like a progress bar to show the code is working to the user.

     

    and handle errors with some logic to show the user that an error happend.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.