title: DBF Large Char Field
body: <p>I have a database file that I beleive was created with Clipper but can't say for sure (I have .ntx files for indexes which I understand is what Clipper uses).  I am trying to create a C# application that will read this database using the System.Data.OleDB namespace.</p>
  
  <p>For the most part I can sucessfully read the contents of the tables there is one field that I cannot.  This field called CTRLNUMS that is defined as a CHAR(750).  I have read various articles found through Google searches that suggest field larger than 255 chars have to be read through a different process than the normal assignment to a string variable.  So far I have not been successful in an approach that I have found.</p>
  
  <p>The following is a sample code snippet I am using to read the table and includes two options I used to read the CTRLNUMS field.  Both options resulted in 238 characters being returned even though there is 750 characters stored in the field.</p>
  
  <p>Here is my connection string:</p>
  
  <p>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\datadir;Extended Properties=DBASE IV;</p>
  
  <p>Can anyone tell me the secret to reading larger fields from a DBF file?</p>
  
  <pre><code>using (OleDbConnection conn = new OleDbConnection(connectionString))
  {
      conn.Open();
  
      using (OleDbCommand cmd = new OleDbCommand())
      {
          cmd.Connection = conn;
          cmd.CommandType = CommandType.Text;
          cmd.CommandText = string.Format("SELECT ITEM,CTRLNUMS FROM STUFF WHERE ITEM = '{0}'", stuffId);
  
          using (OleDbDataReader dr = cmd.ExecuteReader())
          {
              if (dr.Read())
              {
                  stuff.StuffId = dr["ITEM"].ToString();
  
                  // OPTION 1
                  string ctrlNums = dr["CTRLNUMS"].ToString();
  
                  // OPTION 2
                  char[] buffer = new char[750];
                  int index = 0;
                  int readSize = 5;
                  while (index &lt; 750)
                  {
                      long charsRead = dr.GetChars(dr.GetOrdinal("CTRLNUMS"), index, buffer, index, readSize);
  
                      index += (int)charsRead;
  
                      if (charsRead &lt; readSize)
                      {
                          break;
                      }
                  }
              }
          }
      }
  }
  </code></pre>