Hello Dear all
I m new in C# I have project in which I want to import data From Excel to show it in Grid View and save this data in database
in Windows Form not in Asp.net
Please Help Me
Thanks in Advanced
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
venkata kumarPosted Nov 7, 2013, 2:43 AM
the fallowing code will be excel data you can bind to grid view.
DataTable dt = new DataTable();
SqlConnection strConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
strConnection.Open();
string filepath = textBox1.Text;
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=Excel 12.0;"; //Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
excelConnection.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select [ISBN/Code],[Title],[Publisher],[Author],[Qty],[Price],[Rate In INR],[Disc%],[Value In INR] from [Sheet1$]", excelConnection);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
grdInvoiceUploader.DataSource = dt.DefaultView;
}