ADO.NET C# 填充 Excel 表格
我想使用 ADO.NET 任务来实现此目的
:填充 Excel 文件中“RowNum”列的行,从 0 开始。每行将获得从 0 开始的递增值,直到存在的行数。
我想为第一行插入 1,为第二行插入 2,依此类推。请帮助我更新命令和要插入的值。非常感谢。
using (OleDbConnection conn = new OleDbConnection(getExcelConnectionString(new FileInfo(fName))))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand("Update [ExcelFile$] SET RowNum = ? WHERE ............ ", conn);
cmd.Parameters.Add("@rowNumber", OleDbType.Integer).Value =
cmd.ExecuteNonQuery();
}
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(getExcelConnectionString(new FileInfo(fName))))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand("Update [ExcelFile$] SET RowNum = ? WHERE ............ ", conn);
cmd.Parameters.Add("@rowNumber", OleDbType.Integer).Value =
cmd.ExecuteNonQuery();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该会为您指明答案...
http://support.microsoft.com/kb/316934
因此,您可能需要选择所有行,然后在循环中一次更新 1 行以添加 RowNum。
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.
另请查看@此源代码... http://www.codeproject。 com/KB/office/excel_using_oledb.aspx
Also have a peek @ the source code for this... http://www.codeproject.com/KB/office/excel_using_oledb.aspx