ktos1234 ktos1234 - 5 months ago 59
C# Question

Executing Oracle procedure

I connected my oracle database to visual studio and now I'm trying to execute procedure I created in my database.

I tried this:

OracleCommand cmd = new OracleCommand("BEGIN ADD_USER('"+txtName.Text+"','"+txtName2.Text+"',"+txtID.Text+"); END;" );


My procedure has 3 parameters : name, 2name, id. It works fine when I use this command in sqldeveloper, but I get error when I try it in my project.

using (OracleConnection cn = new OracleConnection("con string"))
    OracleCommand cmd = new OracleCommand("ADD_USER");
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = cn;

    cmd.Parameters.AddWithValue(@YourSPParamName1, txtName.Text);
    cmd.Parameters.AddWithValue(@YourSPParamName2, txtName2.Text);
    cmd.Parameters.AddWithValue(@YourSPParamName3, txtID.Text);


Something like this should work.