使用 vb.net 插入 oracle 序列生成的值
我是 VB.net 的新手。我需要修改连接到 Oracle 数据库的现有应用程序。
我的问题是:如何插入由 vb 中的 oracle 序列生成的值? 到目前为止,我有以下代码:
Dim mpData As New MaximoDataSetTableAdapters.MEASUREPOINTTableAdapter
Dim mpTable As New MaximoDataSet.MEASUREPOINTDataTable
mpData.Fill(mpTable)
Dim mData As New MaximoDataSetTableAdapters.MEASUREMENTTableAdapter
Dim mTable As New MaximoDataSet.MEASUREMENTDataTable
Dim mpRow As MaximoDataSet.MEASUREPOINTRow
For Each mpRow In mpTable
Dim mRow As MaximoDataSet.MEASUREMENTRow
mRow = mTable.NewRow()
mRow.POINTNUM = mpRow.POINTNUM
mRow.MEASUREDATE = CStr(Now)
mRow.MEASUREMENTVALUE = tTotal
mTable.Rows.Add(mRow)
mData.Update(mTable)
next
但我收到错误,因为我有另一个字段 ROWSTAMP,它是由序列生成的?
请指教。
问候, 拉杜。
I'm new to VB.net. I need to modify an existing application that connects to an Oracle db.
My question is: How can i insert a value generated by an oracle sequence from vb?
I have the following code so far:
Dim mpData As New MaximoDataSetTableAdapters.MEASUREPOINTTableAdapter
Dim mpTable As New MaximoDataSet.MEASUREPOINTDataTable
mpData.Fill(mpTable)
Dim mData As New MaximoDataSetTableAdapters.MEASUREMENTTableAdapter
Dim mTable As New MaximoDataSet.MEASUREMENTDataTable
Dim mpRow As MaximoDataSet.MEASUREPOINTRow
For Each mpRow In mpTable
Dim mRow As MaximoDataSet.MEASUREMENTRow
mRow = mTable.NewRow()
mRow.POINTNUM = mpRow.POINTNUM
mRow.MEASUREDATE = CStr(Now)
mRow.MEASUREMENTVALUE = tTotal
mTable.Rows.Add(mRow)
mData.Update(mTable)
next
But i receive an error because i have another field, ROWSTAMP, which is generated by a sequence?
Please advice.
Regards,
Radu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Oracle 中,列不是“由序列生成的”。您需要自己从序列中获取下一个值,并在插入行时提供该值:
然后在插入语句中使用 some_variable 中的值。
In Oracle columns are not "generated by a sequence". You need to fetch the next value from a sequence yourself, and supply this value when you insert the row:
Then use the value from some_variable in your insert statement.
您可以创建一个“插入之前”触发器,该触发器使用序列中的下一个值填充 rowstamp 列。我自己不喜欢这种策略,但它是一种选择。
这里有一个如何执行此操作的示例
You can create a "before insert" trigger, which populates the rowstamp column with the next value from a sequence. I don't like this strategy myself, but it is one option.
There is an example of how to do this here