Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've a software in which data is stored in excel database columns are Product_ID & Description. I've included searching feature which displays result based on Product_ID. But the problem is it only retrieves/read/search data when that excel file is open but i want to read data without opening excel file ? Is there any way to do this ???? My code is for searching -:

C#
public Form3()
  {
      InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {
      srch();
  }

  private void srch()
  {
      DataTable sheetData = new DataTable();
      string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= 'c:\\Product Details.xlsx';Extended Properties='Excel 8.0;HDR=Yes;'";
      string query = "select * from [Sheet1$]" ;

      DataSet excelDataSet = new DataSet();
      OleDbDataAdapter da = new OleDbDataAdapter(query, strConn);
      da.Fill(excelDataSet);
      dataGridView1.DataSource = excelDataSet.Tables[0];
      DataView dv = ((DataTable)dataGridView1.DataSource).DefaultView;
      DataView dv_filter = new DataView();
      dv_filter.Table = excelDataSet.Tables[0];
      dv_filter.RowFilter = "Product_ID = '" + textBox1.Text + "'";
      dataGridView1.DataSource = dv_filter;

  }
Posted
Comments
HielturryKory 29-Feb-16 8:59am    
You could use an excel library written in C# for this, the following article demonstrates how to read your excel files in C# (note it does not open the file) and also the following shows how to export that excel's data into a DataTable in C#.

1 solution

 
Share this answer
 

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