Users Pricing

forum

Home Forums Update an entire row in Excel using OleDB command – MindStick

Update an entire row in Excel using OleDB command

Anonymous User 6567 09 Dec 2013

I am trying to blankout/clear an entire excel tab. But nothing seems to work

I tried the following approach:

OleDbConnection connection = new OleDbConnection(connectionString);

OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);

OleDbCommand count = new OleDbCommand("Select count(*) FROM [Sheet1$]", connection);

DataSet dataset = new DataSet();

OleDbDataAdapter adapter = new OleDbDataAdapter();

adapter.SelectCommand = new OleDbCommand("Select * from [Sheet1$]", connection);

adapter.Fill(dataset);

 

for (int i = 0; i < dataset.Tables[0].Rows.Count; i++)

{

    DataRow dtRow = dataset.Tables[0].Rows[i];

    foreach (DataColumn col in dataset.Tables[0].Columns)

    {

        if(col.DataType == typeof(string))

        dataset.Tables[0].Rows[i][col] = "";

   }

}

dataset.Tables[0].AcceptChanges();

adapter.Update(dataset.Tables[0]);


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md