i have a problam to insert data from datagridview to local data base, in my program - im uploading from csv/excel file data to datagridview and showing it to the user .
i have 3 localDB in my program that connected to each other by foreign keys and primary key , i want to insert some columns from the datagridview to my localDB and if that data already exist in my localDB ,dont insert it .
so my questions are:
1.how can i insert properly data from datagridview to my localDB .
2.if its already exist,i dont want to insert it, how to?
this is my code for uploading the file to show in the datagridview :
private void upload_to_datagridview(object sender, EventArgs e)
{
try
{
string Pathconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
OleDbConnection conn = new OleDbConnection(Pathconn);
OleDbDataAdapter myDataAdaptor = new OleDbDataAdapter("Select * from [" + SheetName + "$]", conn);
System.Data.DataTable dt = new System.Data.DataTable();
myDataAdaptor.Fill(dt);
dataGridView1.DataSource = dt;
}
catch(Exception)
{
MessageBox.Show("no workbook was uploaded please upload again!");
wb.Close(false);
excel.Quit();
}
wb.Close(false);
excel.Quit();
}
i have seen some codes for updating data from datagridview to localDB , but it was the whole datagridview , all of the columns , i want to take specific columns from the datagridview and to update specific columns from the dataDB .
please if someone explain me how to do it properly beacause i cant find anything.
thanks!