Mitch3091
Mitch3091

Reputation: 4688

Return Oracle Sequence Nextval into C# Variable

I'm trying to return the nextval from an oracle sequence and save the value into a variable, I´m not expert using Oracle with C# until now I have the connection done and I've used some Oracle packages with c#.

I know that I can use the [sequence_name].nextval into the insert query but for bussiness logic I need the same sequence number for many records and the idea is store the nextval into a variable and pass it like parameter to another c# function that will gonna be the responsible to insert the "n" records into the table.

Any hint or code example gonna be helpful, thanks a lot for the help.

Upvotes: 5

Views: 7063

Answers (1)

PinBack
PinBack

Reputation: 2564

You can get nextval with an OracleCommand

OracleCommand loCmd = Connection.CreateCommand();
loCmd.CommandType = CommandType.Text;
loCmd.CommandText = "select seqname.nextval from dual";
long lnNextVal = Convert.ToInt64(loCmd.ExecuteScalar());

Upvotes: 10

Related Questions