Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a windows application. I have retrieve data from an excel file and display it in a data grid which is working fine. My problem is saving the results from the datagrid to an sql database. Can someone help with some C# code :rolleyes:
Posted

foreach(gridrow object in gridview1.rows)
{
//here get the id of control which you use to show data of excel file
//now save this data in string splited by any character
//like
label lbl = (label)findcontrol("id");
string str= lbl.text+"\";
}
//now insert data into database using split the string value
string [] str1=str.split('\');
//now execute insert query
foreach(string s in str1)
{
insert command
}
 
Share this answer
 
ok,
can u provide your exel file format.so that i can study it
 
Share this answer
 
When u are Loading Data into DataGridView only,
Check already Data Exists in Db or not
if Datanot Exist in Db,
Loop Through the DataTable.Rows.Count or Dataset.Tables[""].Rows.Count
and Run the Insert Statement.
 
Share this answer
 
Comments
Dalek Dave 30-Oct-10 17:56pm    
Good call.

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