开发者

Insert oracle sequence generated value using vb.net

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 MaximoDataSetTableAdapte开发者_如何学运维rs.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.


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜