5

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.

1 Answer 1

10

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());
Sign up to request clarification or add additional context in comments.

1 Comment

perfect I was missing the cmd.ExecuteScalar() part thanks a lot!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.