2015-11-02 55 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调用之前,您需要将其重置为您希望返回的最大值。

相关问题