i have excel file with several columns and i was able import it to my DataGridView in C# Win Forms so user can see and edit the data..
the problem is: how to store the data in the DataGridView to the sql server which stores only available Column on the Database..
this is the quick illustration..


this my current codes..
private void buttonImport_Click(object sender, EventArgs e)
{
if (openFileDialogExcel.FileName != "Excel File")
{
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source='"
+ openFileDialogExcel.FileName + "';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Data$]", MyConnection);
MyCommand.TableMappings.Add("Table", "Student");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
dataGridView1.DataSource = DtSet.Tables[0];
MyConnection.Close();
}
catch (Exception Fail)
{
MessageBox.Show(Fail.ToString());
}
}
else
{
MessageBox.Show("Browse 1st");
}
}
And i have 1 button for saving the data exclude “Gender” Columns..
private void buttonSave_Click(object sender, EventArgs e)
{
-----BLANK :(
}
Thanks in Advance..
If you want to just INSERT these data on the server the most optimum way would be to use Bulk operation…