2015-11-02 38 views
0

我使用以下代碼從基於WBTRV32.dll的BTrieve 6.15數據庫文件中收集數據我在讀取下一個數據庫的位置返回錯誤代碼22 - 是否是一個問題我的BTrieve文件沒有固定列寬?c#Btrieve 6.15錯誤22

// Open file 
RecordBuffer dataBuffer = new RecordBuffer(); 
int bufferLength = System.Runtime.InteropServices.Marshal.SizeOf(dataBuffer); 
short status = (short)BTRCALL(0, positionBlock, ref dataBuffer, ref bufferLength, fileNameArray, 0, 0); 

     if (status == 0) <== Here Status = 0 
     { 
      // Get first record 
      dataBuffer = new RecordBuffer(); 
      status = (short)BTRCALL(12, positionBlock, ref dataBuffer, ref bufferLength, fileNameArray, 0, 0); //BGETFIRST 

      if (status == 0) <== Here Status = 0 
      { 
       ...     
      } 

      // Get subsequent records 
      while (status == 0) // BReturnCodes.END_OF_FILE or an error will occur 
      { 
       dataBuffer = new RecordBuffer(); 
       status = (short)BTRCALL(6, positionBlock, ref dataBuffer, ref bufferLength, fileNameArray, 0, 0); //BGETNEXT 

       if (status == 0) <=== Here Status = 22 data buffer length overrun 
       { 

       } 
      } 

}

回答

1

狀態22層的意思是 「數據緩衝器太短」。根據documentation

將數據緩衝區長度設置爲大於或等於要檢索的記錄長度的值。

您需要確保在每次調用之前將數據緩衝區長度設置爲適當的值。在你的代碼中,你只能設置bufferLength變量一次。如果您有可變長度記錄,那麼該值將設置爲返回到記錄的長度,以便作爲開發人員知道返回的數據量。在下一次GET調用之前,您需要將其重置爲您希望返回的最大值。