使用 vb.net 插入 oracle 序列生成的值

发布于 2024-10-06 04:40:01 字数 760 浏览 5 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自我难过 2024-10-13 04:40:01

在 Oracle 中,列不是“由序列生成的”。您需要自己从序列中获取下一个值,并在插入行时提供该值:

SELECT mysequence.nextval 
  INTO some_variable
FROM dual;

然后在插入语句中使用 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:

SELECT mysequence.nextval 
  INTO some_variable
FROM dual;

Then use the value from some_variable in your insert statement.

街道布景 2024-10-13 04:40:01

您可以创建一个“插入之前”触发器,该触发器使用序列中的下一个值填充 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文