Hello everyone,

I'm working on a little project that use c#, Oracle ODT and asp.net, so, my problem is that i dont know how to convert or store the data retrieved from a sql that is a sequential and then use in other query in the same project.

This is my code, is attached to a button:

protected void Button5_Click(object sender, EventArgs e)
        {
            string oradb = "Data Source=BBDD;User Id=DEMO;Password=DEMO;";
            string cmd1 = "SELECT SECNUM.NEXTVAL FROM DUAL";
            OracleConnection conn = new OracleConnection(oradb);
            conn.Open();

            OracleParameter parm = new OracleParameter();
            parm.OracleDbType = OracleDbType.Decimal;
            
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.Parameters.Add(parm);
            cmd.CommandText = "INSERT INTO DEMOINCI (CODINCI, CODCLI) VALUES (('" + cmd1 +"'), 'TEST')";
           cmd.CommandText = "INSERT INTO DEMOINCILIN (CODINCI,CODLIN) VALUES (('" + cmd1 +"'),1)";
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();                       
        }

So my problem is that the field CODINCI is a field number not a VARCHAR and can not be changed because is already have data, so when I use the code of the example, Oracle return an error saying Invalid number (of course).

I dont know how to store the result of the sequential (SECNUM.NEXTVAL) as number or as an string and then convert it to a number result and then callit into the insert statement, as you see in the example, the cmd1 variable is stored as string but as an string and not like a number. I tried use the convert command Convert.ToInt16(cmd1); but something is not working.

Thanks for all.

You need a OracleDataReader. You can read here for howto and examples.

Hope this help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.