ArrayBinding with null values — oracle-tech

    Forum Stats

  • 3,716,133 Users
  • 2,242,960 Discussions
  • 7,845,840 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

ArrayBinding with null values

3909474
3909474 Member Posts: 2
edited March 2019 in ODP.NET

Hi, I am using ArrayBinding to bulk insert data into Oracle tables. I need to insert null into a column of datatype(number) when the data comes in as empty or null. I have looked at discussion Procedure Array Binding a Null Value  however, for dynamic data, how do we know which row has the null value in it. I used a for loop to get around it, however the data still goes in as 0 into the database.

The code I have used is as below:

                                    OracleParameter name = new OracleParameter();

                                    name.OracleDbType = OracleDbType.Decimal;

                                    name.Value = Array.ConvertAll(columnValues, s => ParseNullableDecimal(s));

                                    name.ArrayBindStatus = new OracleParameterStatus[columnValues.Length];

                                    for (int i=0; i < columnValues.Length; i++)

                                    {

                                        if(string.IsNullOrEmpty(columnValues[i]) || columnValues[i] == DBNull.Value.ToString())

                                        {

                                            name.ArrayBindStatus[i] = OracleParameterStatus.NullInsert;

                                        }

                                    }

                                                                       

                                   

                                    cmd.Parameters.Add(name);

Is there anything missing from above or any suggestions please?

Thanks.

Sign In or Register to comment.