Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Copy data from Datagridview To MS SQL Database

My Datagridview has 4 columns:

ID    Name     Quantity   SafetyQuantity

My MS SQL has 2 columns:

Name         Quantity

and I want to copy from my Datagridview to MS SQL:
Name --> Name
Quantity --> Quantity

How can I do that with VS C#?

1 Solution
on that link, used CommandBuilder
xxxCommandBuilder cmdbuilder = new xxxCommandBuilder(xdataadapter);
xdataadapter.Update(xdatatable, "xyourtable");
Let's see if we can clarify things a wee  bit...

Did the contents of the grid originally come from the SQL Server?  If so, then you'd use the same kind of database features (TableAdapter, DataTables, etc) to send the updated data back to the SQL server.  Typically this would be via the TableAdapter's Update method.

On, the other hand, if the data came from some other source (like an excel spreadsheet, by hand, etc), then you'd need to do a bit more work.
Mohamed AbowardaSoftware EngineerCommented:
Use "for" statement to loop through each row and execute SQL statement to insert each row in the database.

You can also save the data from DataSet to your database:
JameMeckAuthor Commented:
You are right, a little slow, but completed my job.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now