How to avoid the double reading problems when read data from Long Varchar type by ODBC in DBMaker5.2?

~ 0 min
2016-03-18 03:15

Insert a large quantity of pure text data into a column which is Long Varchar type, and then read the contents with JDBATool, the query results are correct. But if we read it with ASP.NET, double contends will be readout. Part of the sample AP code as below.

string strSQL = @"SELECT LNSOURCE FROM TMP_FLNAME WHERE PUBLISH = 'N0'

AND FLCODE = ?;";

OdbcConnection Conn = new OdbcConnection(strConnLaw);

Conn.Open();

OdbcCommand Comm = new OdbcCommand(strSQL, Conn);

Comm.Parameters.Add("FLCODE", OdbcType.Char, 8).Value = hidFLCode.Value.Trim();

OdbcDataReader dr = Comm.ExecuteReader();

if (dr.Read())

{

        // The datatype of LNSOURCE is long varchar

        Response.Write("<pre>" + dr["LNSOURCE"].ToString()+"</pre>");

}

dr.Close();

Conn.Close();

 

We can use OleDb to avoid the double reading problem, but please note that user need to confirm the “Provide” should be”Provider=DMOLE52” but ”Provider=DMOLE52.1”in connection string.

In addition, if users insist on using ODBC, they can avoid the double reading problem by modifying the AP, can be read data by using “GetChars”and add ”CommandBehavior.SequentialAccess”in DataReader.

OdbcDataReader dr = Comm.ExecuteReader(CommandBehavior.SequentialAccess);

  if (dr.Read())

            {

                char[] buffer;

                int iStart = 0;

                long returnLen;

                buffer = new char[256];

                returnLen = dr.GetChars(0, iStart, buffer, 0, 256);

                richTextBox1.Text += new string(buffer);

                while (returnLen > 0)

                {

                    iStart += (int)returnLen;

                    returnLen = dr.GetChars(0, iStart, buffer, 0, 256);

                    richTextBox1.Text += new string(buffer);

                }

            }

            dr.Close();

            Conn.Close();

 

Version: DBMaker 5.x, 4.3

Product: Bundle/Normal

Platform: ALL

Average rating 0 (0 Votes)

You cannot comment on this entry

Tags