Sending clob data via command parameters

Gaurav Gupta 1 Reputation point
2023-10-23T19:20:02.5233333+00:00

I want to send clob data via command parameters. Please suggest how to do that.

i am also using array of parameters values by using command.arraybindcount.s

dont know how to pass the clob value to command parameters

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,411 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 74,536 Reputation points
    2023-10-23T20:12:57.6666667+00:00
    0 comments No comments

  2. KOZ6.0 6,580 Reputation points
    2023-10-24T02:58:19.65+00:00

    Is Oracle? Please reference Oracle.ManagedDataAccess

    using System.Data;
    using Oracle.ManagedDataAccess.Client;
    using Oracle.ManagedDataAccess.Types;
    
    class Program
    {
        static void Main(string[] args)
        {
            using (var con = new OracleConnection())
            {
                con.ConnectionString = ".....";
                con.Open();
    
                using (var cmd = con.CreateCommand())
                {
                    int arraySize = 3;
                    cmd.CommandText = "INSERT INTO TEST_CLOB VALUES (:ITEM_CLOB)";
                    cmd.ArrayBindCount = arraySize;
    
                    var p = new OracleParameter("ITEM_CLOB", OracleDbType.Clob, ParameterDirection.Input);
                    p.Size = arraySize;
                    p.ArrayBindStatus = new OracleParameterStatus[arraySize];
                    var values = new OracleClob[arraySize];
                    for (int i = 0; i < arraySize; i++)
                    {
                        var str = i.ToString();
                        var clob = new OracleClob(con);
                        clob.Write(str.ToCharArray(), 0, str.Length);
                        values[i] = clob;
                    }
                    p.Value = values;
                    cmd.Parameters.Add(p);
    
                    cmd.ExecuteNonQuery();
    
                    for (int i = 0; i < arraySize; i++)
                    {
                        values[i].Dispose();
                    }
                    p.Dispose();
                }
            }
        }
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.