locked
How to update specific rows in excel RRS feed

  • Question

  • User-94554268 posted

    Hey! I need to be able to update multipul specific rows in my excel file.  Is there anyway to do this in a C# asp.net? 

    Here's what  I have:

    protected void Button2_Click(object sender, EventArgs e)
            {
                using (OleDbConnection conn = new OleDbConnection())
                {
                    conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\AIRSIGNDMC\wwwroot\Contract.xlsx;Extended Properties=Excel 12.0 Xml;HDR=NO";
                    string sql = string.Format("UPDATE [Sheet1$A2:A2] SET F1=123456 VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", TextBox1.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text);
                    using (OleDbCommand cmd = new OleDbCommand(sql, conn))
                    {
    
                        try
                        {
                            conn.Open();
                            cmd.ExecuteNonQuery();
                        }
                        
                        finally
                        {
                            conn.Close();
                        }
                        conn.Close();

    as you can see, I need to take the values from texbox1,2... and insert them into specific rows in excel.

    Thank you!

    Wednesday, August 15, 2012 2:44 PM

Answers