Click here to Skip to main content
15,909,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I create a form in visual studio (2015) and add a DataGridView and a button (browse) which get the data from an excel spreadsheet table in my desk and pasted to the DataGridView. Now I'm trying to past the data from the DataGridView in to a sql server table. Can anybody help???

Respectfully,
Pedro Morales

What I have tried:

I was looking for the last 2 day any code, function or class without luck.I can create another table and pasted from that one to the sql table but is not working nether.
Posted
Updated 28-Mar-18 12:29pm

1 solution

You cannot 'paste' data to SQL.
You can open SSMS and open a table in Edit mode and then insert data but that is not the correct way of doing it.

Data is inserted into a database table using an INSERT command, which requires a DbConnection object & a DbCommand object.

If using MSSQL these are SqlConnection and SqlCommand objects but there is other DbConnection & DbCommand objects for other database types.

MSDN References for SQL objects are below;
SqlConnection Class (System.Data.SqlClient)[^]
SqlCommand Class (System.Data.SqlClient)[^]
Additional information, including examples, can be accessed below;
Retrieving and Modifying Data in ADO.NET | Microsoft Docs[^]

Kind Regards
 
Share this answer
 
Comments
Maciej Los 29-Mar-18 4:15am    
5ed!
an0ther1 2-Apr-18 17:17pm    
Thanks Maciej!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900