How to write parameterized oracle insert query?

前端 未结 3 1502
时光说笑
时光说笑 2020-12-09 13:41

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,sala         


        
相关标签:
3条回答
  • 2020-12-09 14:25

    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();
    }
    
    0 讨论(0)
  • 2020-12-09 14:26
       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();
    
    0 讨论(0)
  • 2020-12-09 14:42

    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"));
    
    0 讨论(0)
提交回复
热议问题