作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,所以我是 .NET 的新手,我在使用 ACE.OLEDB 连接更改 Excel 工作表中的更新值时遇到了问题。我不断收到错误消息:无法更新“(表达式)”;字段不可更新。所以我的工作表的结构是这样的:
Symbol AssetClass MarketValue SharePrice
ABC formula $1000 $10.50
MSFT formula $2000 $12
Private m_sConn1 As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PATH_Workbook1 & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;MAXSCANROWS=3;READONLY=FALSE\"""
Dim conn As New OleDbConnection(m_sConn1)
conn.Open()
Dim cmd As New OleDbCommand()
cmd.Connection = conn
Dim da As New OleDbDataAdapter("Select * From [HoldingsTest$]", conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds, "HoldingsTable")
' Generate the UpdateCommand and add the parameters for the command.
da.UpdateCommand = New OleDbCommand("UPDATE [HoldingsTest$] SET AssetClass =?, MarketValue =?, SharePrice = ? WHERE Symbol = ?", conn)
da.UpdateCommand.Parameters.Add("@AssetClass", OleDbType.VarChar).SourceColumn = "AssetClass"
da.UpdateCommand.Parameters.Add("@MarketValue", OleDbType.Currency).SourceColumn = "MarketValue"
da.UpdateCommand.Parameters.Add("@SharePrice", OleDbType.Currency).SourceColumn = "SharePrice"
da.UpdateCommand.Parameters.Add("@Symbol", OleDbType.VarChar, 9, "Symbol")
' Update records
ds.Tables(0).Rows(1)("AssetClass") = "formula"
ds.Tables(0).Rows(1)("MarketValue") = 101
ds.Tables(0).Rows(1)("SharePrice") = 91
' Apply the dataset changes to the actual data source (the workbook).
da.Update(ds, "HoldingsTable")
最佳答案
在 How To Use ADO with Excel Data from Visual Basic or VBA 上提到了它,
"You can edit Excel data with the normal ADO methods. Recordset fields which correspond to cells in the Excel worksheet containing Excel formulas (beginning with "=") are read-only and cannot be edited"
关于.net - 更新 Excel 工作表 : Cannot update '(expression)' ; field not updateable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17814631/
我是一名优秀的程序员,十分优秀!