4

I am using oracle as my back end and i write insert query as follows, i don't know is it correct way are not,

insert into Emp_table (SL_NO,empane,empid,salaray) values(1,'sree',1002 ,:salary);

here in query i am calculating salary with stored procedure and getting as my out parameter salary so i has to pass that to my insert query so how can i write. if i write like as shown i am getting below errors

ORA-06550: line 1, column 175:
PL/SQL: ORA-00933: SQL command not properly ended
ORA-06550: line 1, column 7:
PL/SQL: SQL Statement ignored

kindly help me.

3 Answers 3

13

Microsoft deprecated their Oracle provider (System.Data.OracleClient) so use a third party provider such as Oracle's Data Provider for .NET. The code example below is essentially the same as FSX's answer, just without the convenience of the AddWithValue method.

command.Parameters.Add(new OracleParameter("SL_NO", 1));
command.Parameters.Add(new OracleParameter("empane", "sree"));
Sign up to request clarification or add additional context in comments.

2 Comments

Please note that you have written 'New OracleParameter' => 'n' shouldn't be in capital letter in the 'new' keyword.
Thanks, Nishanth. Converted from VB to C#.
10

Assuming salary amount is 20000, You can try this code:

var commandText = "insert into Emp_table (SL_NO,empane,empid,salaray) values(:SL_NO,:empane,:empid,:salary)";

using (OracleConnection connection = new OracleConnection(connectionString))
using (OracleCommand command = new OracleCommand(commandText, connection))
{
    command.Parameters.AddWithValue("SL_NO", 1);
    command.Parameters.AddWithValue("empane", "sree");
    command.Parameters.AddWithValue("empid", 1002);
    command.Parameters.AddWithValue("salaray", 20000);
    command.Connection.Open();
    command.ExecuteNonQuery();
    command.Connection.Close();
}

Comments

2
   strin sql= "insert into Emp_table (SL_NO,empane,empid,salaray) values(:SL_NO,:empane,:empid,:salary)";
    OracleCommand command = new OracleCommand(sql, connection)
    command.Parameters.Add(new OracleParameter("SL_NO", 1);
    command.Parameters.Add(new OracleParameter("empane", "sree"));
    command.Parameters.Add(new OracleParameter(("empid", 1002));
    command.Parameters.Add(new OracleParameter(("salaray", 20000));
    command.Connection.Open();
    command.ExecuteNonQuery();
    command.Connection.Close();

1 Comment

I get error while adding Zero. For ex: ("salary",0).. Salary is defined as NUMBER in Oracle. @AshishModi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.