コード例 #1
0
        public void UpdateColumn(int col, Array values)
        {
            using (FileStream fs = new FileStream(this._file, FileMode.Open, FileAccess.ReadWrite))
            {
                // Move to the start of the first row.
                this.MoveStreamToRow(0, fs);

                // Jump to the start of the field.
                this.MoveStreamToField(col, fs);

                // Then, write each value and then skip the size of a full
                //   record, minus the updated field length, which should
                //   put the Stream's position at the start of that same
                //   field for the next record.
                int recSize = (this._hdr.RecordSize + 1) - this._hdr.Fields[col].FieldLength;
                foreach (object obj in values)
                {
                    DbfTable.WriteDbfField(fs, this._hdr.Fields[col], obj);
                    // If the total numer of bytes read does not match the determined
                    //   number of bytes to skip for each record, it means we hit
                    //   the end of the file.
                    if (fs.Read(new byte[recSize], 0, recSize) != recSize)
                    {
                        break;
                    }
                }

                // And set the LastUpdateDate value in the header.
                DbfTable.SetLastUpdateTime(fs);
            }
        }
コード例 #2
0
        /// <summary>
        /// Writes a full record to a DBF file using the provided Stream object.  This method assumes the Stream object's write position is located at the position to begin writing.  The record's 'DeletionFlag' value will automatically be set to 0x00.
        /// </summary>
        /// <param name="s">An initialized Stream object of a DBF file with the cursor position set to the beginning of record to be written.</param>
        /// <param name="flds">A DbfFieldCollection detailing the structure of the DBF file being writen to.</param>
        /// <param name="values">An Array.Object value containing the values to write into the DBF record.</param>
        public static void WriteDbfRecord(Stream s, DbfFieldCollection flds, Array values)
        {
            // The first byte of every record is the deletion flag.  This method
            //   assumes the given Stream is at the beginning of the record.
            s.WriteByte(0x00);

            // For each DbfField and value pair, write the data to
            //   the given Stream object.
            for (int i = 0; i < System.Math.Min(flds.Count, values.Length); i++)
            {
                DbfTable.WriteDbfField(s, flds[i], values.GetValue(i));
            }
        }
コード例 #3
0
        public void UpdateValue(long row, int col, object value)
        {
            using (FileStream fs = new FileStream(this._file, FileMode.Open, FileAccess.ReadWrite))
            {
                // Move to the start of the selected row.
                this.MoveStreamToRow(row, fs);

                // Move stream to selected field.
                this.MoveStreamToField(col, fs);

                // Write the data using the static method.
                DbfTable.WriteDbfField(fs, this._hdr.Fields[col], value);
            }
        }