c# Btrieve 6.15 error 22

本文关键字:error Btrieve | 更新日期: 2023-09-27 18:20:08

我使用以下代码从基于WBTRV32.dll的BTrieve 6.15数据库文件中收集数据我一直在读取下一条数据线的位置得到错误代码22——我的BTrieve文件没有固定的列宽是问题吗?

// 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
                {
                }
            }

}

c# Btrieve 6.15 error 22

状态22表示"数据缓冲区太短"。根据文件:

将"数据缓冲区长度"设置为大于或等于要检索的记录长度的值。

在每次调用之前,您需要确保"数据缓冲区长度"设置为正确的值。在代码中,只设置了一次bufferLength变量。如果您有可变长度的记录,那么在返回记录长度时会设置该值,这样作为开发人员,您就可以知道返回了多少数据。在下一次GET调用之前,您需要将其重置为期望返回的最大值。