开发者

ADO.NET c# Populate excel table

I want to achieve this using ADO.NET

Task: Populate the rows of the column "RowNum" in the excel file staring from 0. each row will get an incremented value starting from 0 until the number of rows present.

I want to insert 1 for the first row, 2 for the second row, and so on. please help me with the update command and the value to be inserted. Thank you very much.

using (OleDbConnection conn = new OleDbConnection(getExcelConnectionStri开发者_Go百科ng(new FileInfo(fName))))
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand("Update [ExcelFile$] SET RowNum = ? WHERE ............ ", conn);

                    cmd.Parameters.Add("@rowNumber", OleDbType.Integer).Value = 
                    cmd.ExecuteNonQuery();
            }


This should point you to the answer...

http://support.microsoft.com/kb/316934

So you probably need to select all the rows then update them 1 at a time in a loop to add the RowNum.


Also have a peek @ the source code for this... http://www.codeproject.com/KB/office/excel_using_oledb.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜