0

I am have created some function to read data form excel file using, OleDbConnection, OleDbDataAdapter, DataSet. I am able to read data successfully using sheet name, row, column number.

I function using same to update value of excel sheet by passing row and column number.

I need some help,

Thanks in advance.

1

1 Answer 1

1

Unless you have a strong reason for using OleDb for this, I recommend against it. The usage is very limited and archaic and the providers are no longer shipped with Office 2013 or in Windows. NuGet EPPlus and make your life a lot easier.

However, here is an example of how to do an insert and update using OleDb:

        using (OleDbConnection cn = new OleDbConnection(connectionString))
        {
            cn.Open();
            using (OleDbCommand cmd1 = new OleDbCommand("INSERT INTO [MySheet$] (COLUMN1, COLUMN2) VALUES ('Count', 1);", cn))
            {
                cmd1.ExecuteNonQuery();
            }

            using (OleDbCommand cmd1 = new OleDbCommand("UPDATE [MySheet$] SET COLUMN2 = 5 WHERE ID = 1", cn))
            {
                cmd1.ExecuteNonQuery();
            }
        }
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for you quick reply, I have no unique key where I can use where condition, can update value only based ob row and column
There is a special column named ID, which holds the row number. I have updated my example to update based off of this. I do not believe you can select ID as a column in a select statement, even though it can be used in the where clause.
Thanks mikdav, your explanation in details, I will work in accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.