954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem store a oracle sql result into a variable

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.

cavemanweb
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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

Hope this help.

lolafuertes
Master Poster
793 posts since Oct 2008
Reputation Points: 120
Solved Threads: 166
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: