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

x
  • 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#?

0
JameMeck
Asked:
JameMeck
1 Solution
 
systanCommented:
http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c13041
on that link, used CommandBuilder
eq.,
xxxCommandBuilder cmdbuilder = new xxxCommandBuilder(xdataadapter);
xdataadapter.Update(xdatatable, "xyourtable");
0
 
grayeCommented:
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.
0
 
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:
http://msdn.microsoft.com/en-us/library/xzb1zw3x(v=vs.80).aspx
0
 
JameMeckAuthor Commented:
You are right, a little slow, but completed my job.
0

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