-1

I'm using C# with oracle ODP.NET to query a table, and it seems to have a odd behavior if the field value has the symbol "%". As the following example:

In Oracle (11g or 12c) I run the following command to create a test table inserting the values with the symbol %

CREATE TABLE "TESTCHAR" ("NAME" VARCHAR2(255 BYTE) NOT NULL ENABLE, "RESULT" VARCHAR2(4000 BYTE));
COMMIT;

INSERT INTO TESTCHAR (NAME, RESULT) VALUES ('Test 1 % Area','10');
INSERT INTO TESTCHAR (NAME, RESULT) VALUES ('Test 2 % Area','10');
INSERT INTO TESTCHAR (NAME, RESULT) VALUES ('Test 3 % Area','10');
INSERT INTO TESTCHAR (NAME, RESULT) VALUES ('Test 4 % Area','10');
INSERT INTO TESTCHAR (NAME, RESULT) VALUES ('Test 5 % Area','10');
INSERT INTO TESTCHAR (NAME, RESULT) VALUES ('Test 6 % Area','10');
COMMIT;

Now in a simple windows form application in Visual Studio (used 2012 and 2015) I just create the following app:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OracleConnection conn = new OracleConnection("User Id=myUser;Password=myPass;Data Source=myData");
            conn.Open();
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "select * from testchar";
            cmd.CommandType = CommandType.Text;
            OracleDataReader dr = cmd.ExecuteReader();
            dr.Read();
            DataTable dt = new DataTable();
            dt.Load(dr);
            dataGridView1.DataSource = dt;
        }
    }
}

It will pops up only 5 rows in the datagrid. But if you goes directly to SQL Developer and uses the same query, it will return all rows. I've already tried the managed and unmanaged odp.net. It seems to be a bad interpretation in the oracle provider.

If you use System.Data.OleDb this problem does not occurs, but I cannot use it as we deal with Clob type.

Does anybody know a solution for this problem?

Thansk all!

F_Fernando
  • 11
  • 2
  • 2
    remove the line: dr.Read(); and what happens? – tbone Sep 02 '16 at 20:19
  • Hi @tbone, did a quick test and it seems that removing the dr.Read() solve the problem. I'll test next week with the entire code and let you know the results!!! – F_Fernando Sep 02 '16 at 21:03
  • Hey @tbone, your comment solved the code. Without the dr.Read() works just fine! Thanks a lot for your help. – F_Fernando Sep 07 '16 at 12:41
  • No problem, the Read() method will advance the reader to the next record, which is why you got only 5 of the 6 rows. – tbone Sep 07 '16 at 14:34

1 Answers1

1

Removing the dr.Read() from the code solved the problem!

Thanks @tbone for your help.

F_Fernando
  • 11
  • 2