Take the 2-minute tour ×

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

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.MEASUREDATE = CStr(Now)


But i receive an error because i have another field, ROWSTAMP, which is generated by a sequence?

Please advice.

Regards, Radu.

share|improve this question

2 Answers 2

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.

share|improve this answer
I know this. But i need the vb.net code to insert values in the table using the sequence. –  Radu Dragomir Dec 3 '10 at 11:27
So you cannot run this query from within VB.net and use the returned value in your VB code? –  a_horse_with_no_name Dec 3 '10 at 12:09

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

share|improve this answer

Your Answer


