Results 1 to 3 of 3

Thread: SQL BULK INSERT FROM DataGridView

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    43

    SQL BULK INSERT FROM DataGridView

    Hey all,

    I need some help figureing out how to insert the contents of a datagridview into an SQL database table. some of the columns are databound and some are not. in otherwords, some columns i need to insert the "Value" of the cell while others i will need to insert the "Text" of the cell.

    any suggestions?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: SQL BULK INSERT FROM DataGridView

    Is your DGV databound? If it is, you just use a dataadapter to update the datatable that it is bound to. Otherwise, you have to loop thru the DGV rows and insert one at a time using a SqlCommand.

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

    Re: SQL BULK INSERT FROM DataGridView

    You should put all your data into a DataTable and then use a DataAdapter or TableAdapter to Update the source table from the DataTable. If you have bound and unbound columns in your grid then you should loop through all the rows of the grid and perform whatever processing is needed to get the unbound data into the remaining columns of the DataTable. You then just call Update on the adapter and pass the table. This assumes that your adapter has the appropriate InsertCommand and UpdateCommand properties for the data your DataTable contains.
    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

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