ktos1234 ktos1234 - 1 year ago 118
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.

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download