How to read data from Excel 2007 to RDLC Report by c# window [Resolved]

Posted by Ahmedsa under C# on 1/23/2017 | Points: 10 | Views : 477 | Status : [Member] | Replies : 1
I work in windows form c# visual studio 2015

I have file xlsx excel 2007 and i need to read data from Excel and show on Report Rdlc

in windows form by using c#

So that How can i Read data by c# from Excel and display in Rdlc windows form ?




Responses

Posted by: A2H on: 1/23/2017 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
To add RDLC and the steps for configuring you can refer the below link. Follow the steps exactly as mentioned in the link
http://www.aspsnippets.com/Articles/RDLC-Report-in-Windows-Forms-WinForms-Application-using-C-and-VBNet.aspx

Once you add the reportviewer, RDLC and DataSet you can use the below codein code behind of WIndow form to read fromexcel
  public Form1()
{
InitializeComponent();
string pathofexecutable = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

OleDbConnection oledbConn = null;
oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathofexecutable + "\\Book3105.xlsx;Mode=ReadWrite;Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';");
oledbConn.Open();

DataSet ds = new DataSet();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = oledbConn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM [sheet1$]";
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda = new OleDbDataAdapter(cmd);
oleda.Fill(ds);
ds.Tables[0].TableName = "DataTable1";

this.DataTable1BindingSource.DataSource = ds;
this.reportViewer2.RefreshReport();

}


Thanks,
A2H
My Blog

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response