Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 -:

  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 15-Jul-13 20:38pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 393
1 Sascha Lefévre 215
2 Abhinav S 170
3 Richard Deeming 155
4 CHill60 150
0 Sergey Alexandrovich Kryukov 7,141
1 OriginalGriff 6,410
2 Maciej Los 2,832
3 Abhinav S 2,732
4 Peter Leow 2,694


Advertise | Privacy | Mobile
Web03 | 2.8.150414.1 | Last Updated 16 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100