Click here to Skip to main content
15,900,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i used this code

private void btnshow_Click(object sender, EventArgs e)
    string connStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\KBE\\solid piston1.xls';Extended Properties=Excel 8.0;";
    OleDbConnection MyConnection;
    DataSet ds1;
    OleDbDataAdapter MyCommand1;
    MyConnection = new OleDbConnection(connStr);
    MyCommand1 = new OleDbDataAdapter("select * from [INPUT$]", MyConnection);
    ds1 = new System.Data.DataSet();
    DataTable dt1 = new DataTable();
    dt1 = ds1.Tables[0];

    cbf.Items.Insert(0, dt1.Rows[1]["Value"].ToString());

    textBox1.Text = dt1.Rows[2]["Value"].ToString();
    textBox2.Text = dt1.Rows[3]["Value"].ToString();
    textBox3.Text = dt1.Rows[4]["Value"].ToString();
    textBox4.Text = dt1.Rows[5]["Value"].ToString();
    comboBox2.Text = dt1.Rows[6]["Value"].ToString();

    textBox5.Text = dt1.Rows[7]["Value"].ToString();
    textBox6.Text = dt1.Rows[8]["Value"].ToString();
    textBox7.Text = dt1.Rows[9]["Value"].ToString();
    cbr.Text = dt1.Rows[10]["Value"].ToString();
    // textBox46.Text = dt1.Rows[11]["Value"].ToString();
    comboBox4.Text = dt1.Rows[12]["Value"].ToString();
    textBox8.Text = dt1.Rows[13]["Value"].ToString();

    textBox19.Text = dt1.Rows[24]["Value"].ToString();
    comboBox5.Text = dt1.Rows[25]["Value"].ToString();
    textBox20.Text = dt1.Rows[26]["Value"].ToString();
    textBox21.Text = dt1.Rows[27]["Value"].ToString();

    textBox22.Text = dt1.Rows[28]["Value"].ToString();
    textBox23.Text = dt1.Rows[29]["Value"].ToString();
    textBox24.Text = dt1.Rows[30]["Value"].ToString();
    textBox17.Text = dt1.Rows[22]["Value"].ToString();



whenever i click button new excel open in the task manager so problem occur in application .
so please give me suggestion to clean the excel from the task manager

Updated 8-Jan-14 20:40pm

at the end of the function, you write like this..

 MyConnection = null;
MyCommand1 = null;
Share this answer
The OleDbConnection class implements IDisposable[^] so you can use the using keyword. This means that when the using block goes out of scope, the connection will clean up after itself. Read this[^] article to get a basic understanding of the IDisposable interface.
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