### Install NDbfReader NuGet Package Source: https://github.com/bloggerdude/ndbf/blob/master/README.md Installs the NDbfReader package using the Package Manager Console in Visual Studio. ```powershell Install-Package NDbfReader ``` -------------------------------- ### Table.Open - Opening a dBASE Table from File Path Source: https://context7.com/bloggerdude/ndbf/llms.txt Opens a dBASE table from a file path on disk. The returned Table object is disposable and should be used within a 'using' statement. ```APIDOC ## Table.Open - Opening a dBASE Table from File Path ### Description Opens a dBASE table from a file path on disk. This is the primary entry point for reading DBF files. The method returns a disposable `Table` object that should be used within a `using` statement to ensure proper resource cleanup. ### Method `Table.Open(string filePath)` ### Endpoint N/A (Library method) ### Parameters #### Path Parameters - **filePath** (string) - Required - The full path to the .dbf file. ### Request Example ```csharp using NDbfReader; using System; // Open a dBASE file from a file path using (var table = Table.Open(@"C:\Data\customers.dbf")) { // Access table metadata Console.WriteLine($"Last modified: {table.LastModified}"); Console.WriteLine($"Number of columns: {table.Columns.Count}"); // List all columns with their types and sizes foreach (var column in table.Columns) { Console.WriteLine($" Column: {column.Name}, Type: {column.Type.Name}, Size: {column.Size}"); } // Open a reader to iterate through rows var reader = table.OpenReader(); while (reader.Read()) { // Process each row var id = reader.GetValue("ID"); var name = reader.GetString("NAME"); Console.WriteLine($"ID: {id}, Name: {name}"); } } ``` ### Response #### Success Response (Table Object) - **Table** (IDisposable) - An object representing the opened dBASE table, providing access to metadata and a reader. #### Response Example (See Request Example for usage) ``` -------------------------------- ### Open dBASE Table from File Path Source: https://context7.com/bloggerdude/ndbf/llms.txt Opens a dBASE table from a file path. Ensure the Table object is disposed using a 'using' statement for resource management. This method allows access to table metadata and row iteration. ```csharp using NDbfReader; using System; // Open a dBASE file from a file path using (var table = Table.Open(@"C:\Data\customers.dbf")) { // Access table metadata Console.WriteLine($"Last modified: {table.LastModified}"); Console.WriteLine($"Number of columns: {table.Columns.Count}"); // List all columns with their types and sizes foreach (var column in table.Columns) { Console.WriteLine($" Column: {column.Name}, Type: {column.Type.Name}, Size: {column.Size}"); } // Open a reader to iterate through rows var reader = table.OpenReader(); while (reader.Read()) { // Process each row var id = reader.GetValue("ID"); var name = reader.GetString("NAME"); Console.WriteLine($"ID: {id}, Name: {name}"); } } ``` -------------------------------- ### Asynchronously Open dBASE Table Source: https://context7.com/bloggerdude/ndbf/llms.txt Opens a dBASE table asynchronously from a file path or stream, suitable for I/O-bound operations in async/await contexts. Supports asynchronous row reading. ```csharp using NDbfReader; using System; using System.Threading.Tasks; public async Task ProcessDbfAsync(string filePath) { // Open table asynchronously from file path using (var table = await Table.OpenAsync(filePath)) { Console.WriteLine($"Loaded table with {table.Columns.Count} columns"); // Open reader and read rows asynchronously var reader = table.OpenReader(); int rowCount = 0; while (await reader.ReadAsync()) { rowCount++; var name = reader.GetString("NAME"); var value = reader.GetDecimal("AMOUNT"); Console.WriteLine($"Row {rowCount}: {name} = {value}"); } Console.WriteLine($"Total rows processed: {rowCount}"); } } // Using with async stream public async Task ProcessStreamAsync(Stream stream) { using (var table = await Table.OpenAsync(stream)) { var reader = table.OpenReader(); while (await reader.ReadAsync()) { // Process rows asynchronously } } } ``` -------------------------------- ### Table.OpenAsync - Asynchronously Opening a dBASE Table Source: https://context7.com/bloggerdude/ndbf/llms.txt Opens a dBASE table asynchronously, ideal for I/O-bound operations in async/await contexts. Supports both file paths and streams. ```APIDOC ## Table.OpenAsync - Asynchronously Opening a dBASE Table ### Description Opens a dBASE table asynchronously, ideal for I/O-bound operations in async/await contexts. Supports both file paths and streams for maximum flexibility in async applications. ### Method `Task Table.OpenAsync(string filePath)` `Task
Table.OpenAsync(Stream stream)` ### Endpoint N/A (Library method) ### Parameters #### Path Parameters - **filePath** (string) - Required - The full path to the .dbf file (for the file path overload). - **stream** (Stream) - Required - The readable stream containing the .dbf file data (for the stream overload). ### Request Example ```csharp using NDbfReader; using System; using System.Threading.Tasks; public async Task ProcessDbfAsync(string filePath) { // Open table asynchronously from file path using (var table = await Table.OpenAsync(filePath)) { Console.WriteLine($"Loaded table with {table.Columns.Count} columns"); // Open reader and read rows asynchronously var reader = table.OpenReader(); int rowCount = 0; while (await reader.ReadAsync()) { rowCount++; var name = reader.GetString("NAME"); var value = reader.GetDecimal("AMOUNT"); Console.WriteLine($"Row {rowCount}: {name} = {value}"); } Console.WriteLine($"Total rows processed: {rowCount}"); } } // Using with async stream public async Task ProcessStreamAsync(Stream stream) { using (var table = await Table.OpenAsync(stream)) { var reader = table.OpenReader(); while (await reader.ReadAsync()) { // Process rows asynchronously } } } ``` ### Response #### Success Response (Table Object) - **Table** (Task) - A task that, when completed, returns an object representing the opened dBASE table, providing access to metadata and a reader. #### Response Example (See Request Example for usage) ``` -------------------------------- ### Accessing Table Schema with ColumnCollection Source: https://context7.com/bloggerdude/ndbf/llms.txt Demonstrates accessing column information by index and name, and iterating through columns to identify string types. Requires opening a DBF table. ```csharp using NDbfReader; using System; using (var table = Table.Open(@"C:\Data\schema_example.dbf")) { ColumnCollection columns = table.Columns; Console.WriteLine($"Table has {columns.Count} columns:"); Console.WriteLine(); // Access by index for (int i = 0; i < columns.Count; i++) { IColumn column = columns[i]; Console.WriteLine($ ``` ```csharp [{i}] {column.Name} Console.WriteLine($" CLR Type: {column.Type.Name}"); Console.WriteLine($" Size: {column.Size} bytes"); Console.WriteLine(); } // Access by name if (columns["CUSTOMER_ID"] != null) { IColumn idColumn = columns["CUSTOMER_ID"]; Console.WriteLine($"Found ID column with size {idColumn.Size}"); } // Iterate using foreach Console.WriteLine("All string columns:"); foreach (var column in columns) { if (column.Type == typeof(string)) { Console.WriteLine($" {column.Name} ({column.Size} chars)"); } } } ``` -------------------------------- ### Extending HeaderLoader for Custom Column Types Source: https://context7.com/bloggerdude/ndbf/llms.txt Provides a custom HeaderLoader to handle 'M' (Memo) and 'B' (Binary/Double) column types by treating them as raw bytes. This allows for custom parsing or handling of non-standard DBF field types. ```csharp using NDbfReader; using System; using System.IO; // Custom header loader that handles additional column types public class ExtendedHeaderLoader : HeaderLoader { protected override Column CreateColumn(byte size, byte type, string name, int columnOffset) { // Handle custom column types switch (type) { case (byte)'M': // Memo field - treat as raw bytes Console.WriteLine($"Found memo field: {name}"); return new RawColumn(name, columnOffset, size, type); case (byte)'B': // Binary/Double - treat as raw Console.WriteLine($"Found binary field: {name}"); return new RawColumn(name, columnOffset, size, type); default: // Use default handling for standard types return base.CreateColumn(size, type, name, columnOffset); } } } // Usage public void ProcessWithCustomLoader(string filePath) { using (var stream = File.OpenRead(filePath)) { var customLoader = new ExtendedHeaderLoader(); using (var table = Table.Open(stream, customLoader)) { Console.WriteLine($"Loaded {table.Columns.Count} columns with custom loader"); var reader = table.OpenReader(); while (reader.Read()) { // Process rows } } } } ``` -------------------------------- ### Open and Read DBF Table Source: https://github.com/bloggerdude/ndbf/blob/master/README.md Opens a DBF file and reads its content row by row. Specify the encoding if it's not UTF-8. Requires using System.Text.Encoding. ```csharp using (var table = Table.Open("D:\\foo.dbf")) { // UTF-8 is the default encoding var reader = table.OpenReader(Encoding.GetEncoding(1250)); while(reader.Read()) { var name = reader.GetString("NAME"); //... } } ``` -------------------------------- ### Open DBF Table and Create Row Reader with Encoding Source: https://context7.com/bloggerdude/ndbf/llms.txt Opens a DBF table and creates a forward-only reader. Supports default UTF-8 encoding or custom encodings for legacy files. Only one reader can be open per table at a time. ```csharp using NDbfReader; using System; using System.Text; using (var table = Table.Open(@"C:\Data\czech_data.dbf")) { // Open reader with default UTF-8 encoding var readerUtf8 = table.OpenReader(); // Or specify a custom encoding for legacy files // Central European (Windows-1250) encoding var readerCzech = table.OpenReader(Encoding.GetEncoding(1250)); // Western European (Windows-1252) encoding // var readerWestern = table.OpenReader(Encoding.GetEncoding(1252)); Console.WriteLine($"Reader encoding: {readerCzech.Encoding.EncodingName}"); while (readerCzech.Read()) { // String values are decoded using the specified encoding string cityName = readerCzech.GetString("MESTO"); Console.WriteLine($"City: {cityName}"); } } ``` -------------------------------- ### Asynchronously Load DBF Data with C# Source: https://context7.com/bloggerdude/ndbf/llms.txt Performs non-blocking I/O operations to load DBF data, suitable for UI or web applications. ```csharp using NDbfReader; using System; using System.Data; using System.Text; using System.Threading.Tasks; public async Task LoadDataAsync(string filePath) { using (var table = await Table.OpenAsync(filePath)) { // Load entire table asynchronously DataTable dataTable = await table.AsDataTableAsync(); return dataTable; } } // With encoding and column selection public async Task LoadSelectedColumnsAsync(string filePath, params string[] columns) { using (var table = await Table.OpenAsync(filePath)) { DataTable dataTable = await table.AsDataTableAsync( Encoding.GetEncoding(1252), columns ); return dataTable; } } // Usage example public async Task ProcessSalesDataAsync() { var salesData = await LoadSelectedColumnsAsync( @"C:\Data\sales.dbf", "DATE", "PRODUCT", "AMOUNT", "REGION" ); decimal total = 0; foreach (DataRow row in salesData.Rows) { if (row["AMOUNT"] != DBNull.Value) { total += Convert.ToDecimal(row["AMOUNT"]); } } Console.WriteLine($"Total sales: ${total:N2}"); } ``` -------------------------------- ### AsDataTableAsync - Asynchronously Loading Table into DataTable Source: https://context7.com/bloggerdude/ndbf/llms.txt Asynchronously loads the dBASE table into a DataTable, ideal for responsive UI applications or web services where blocking I/O should be avoided. Supports loading all columns or specific columns with custom encoding. ```APIDOC ## AsDataTableAsync - Asynchronously Loading Table into DataTable ### Description Asynchronously loads the dBASE table into a DataTable, ideal for responsive UI applications or web services where blocking I/O should be avoided. ### Method `await Table.OpenAsync(filePath).AsDataTableAsync()` or `await Table.OpenAsync(filePath).AsDataTableAsync(encoding, columns)` ### Parameters #### Path Parameters - **filePath** (string) - Required - The path to the DBF file. #### Query Parameters None #### Request Body None #### Method Overloads - `AsDataTableAsync()`: Loads the entire table asynchronously with default UTF-8 encoding. - `AsDataTableAsync(Encoding encoding, params string[] columns)`: Loads specified columns asynchronously with a custom encoding. ### Request Example ```csharp using NDbfReader; using System.Data; using System.Text; using System.Threading.Tasks; public async Task LoadDataAsync(string filePath) { using (var table = await Table.OpenAsync(filePath)) { // Load entire table asynchronously DataTable dataTable = await table.AsDataTableAsync(); return dataTable; } } public async Task LoadSelectedColumnsAsync(string filePath, params string[] columns) { using (var table = await Table.OpenAsync(filePath)) { DataTable dataTable = await table.AsDataTableAsync( Encoding.GetEncoding(1252), columns ); return dataTable; } } // Usage example public async Task ProcessSalesDataAsync() { var salesData = await LoadSelectedColumnsAsync( @"C:\Data\sales.dbf", "DATE", "PRODUCT", "AMOUNT", "REGION" ); decimal total = 0; foreach (DataRow row in salesData.Rows) { if (row["AMOUNT"] != DBNull.Value) { total += Convert.ToDecimal(row["AMOUNT"]); } } Console.WriteLine($"Total sales: ${total:N2}"); } ``` ### Response #### Success Response (Task) - **Task** - A Task that, when completed, returns an ADO.NET DataTable containing the data from the DBF file. #### Response Example ```csharp // The returned DataTable can be processed as shown in previous examples. // For instance, iterating through rows: foreach (DataRow row in salesData.Rows) { Console.WriteLine($"Product: {row["PRODUCT"]}, Amount: {row["AMOUNT"]}"); } ``` ``` -------------------------------- ### Open dBASE Table from Stream Source: https://context7.com/bloggerdude/ndbf/llms.txt Opens a dBASE table from any readable stream, including non-seekable ones. The stream is automatically closed upon disposal of the Table object. Useful for handling uploaded files or network streams. ```csharp using NDbfReader; using System.IO; using System.Net.Http; // Example: Reading from a MemoryStream byte[] dbfBytes = File.ReadAllBytes(@"C:\Data\products.dbf"); using (var stream = new MemoryStream(dbfBytes)) using (var table = Table.Open(stream)) { var reader = table.OpenReader(); while (reader.Read()) { Console.WriteLine(reader.GetString("PRODUCT_NAME")); } } // Example: ASP.NET file upload handling // [HttpPost] // public ActionResult Upload(HttpPostedFileBase file) // { // using (var table = Table.Open(file.InputStream)) // { // var reader = table.OpenReader(); // while (reader.Read()) // { // // Process uploaded DBF data // } // } // } ``` -------------------------------- ### Load Entire Table into DataTable with C# Source: https://context7.com/bloggerdude/ndbf/llms.txt Loads all rows and columns from a DBF file into memory. Supports optional custom encoding. ```csharp using NDbfReader; using System; using System.Data; using System.Text; // Load entire table with default UTF-8 encoding using (var table = Table.Open(@"C:\Data\customers.dbf")) { DataTable dataTable = table.AsDataTable(); Console.WriteLine($"Loaded {dataTable.Rows.Count} rows"); // Work with DataTable foreach (DataRow row in dataTable.Rows) { Console.WriteLine($"Customer: {row["NAME"]}, City: {row["CITY"]}"); } } // Load with specific encoding using (var table = Table.Open(@"C:\Data\legacy_data.dbf")) { DataTable dataTable = table.AsDataTable(Encoding.GetEncoding(1252)); // Use LINQ with DataTable var filtered = dataTable.AsEnumerable() .Where(r => r.Field("COUNTRY") == "USA") .OrderBy(r => r.Field("NAME")); foreach (var row in filtered) { Console.WriteLine(row["NAME"]); } } ``` -------------------------------- ### Table.Open (Stream) - Opening a dBASE Table from Stream Source: https://context7.com/bloggerdude/ndbf/llms.txt Opens a dBASE table from any readable stream, including non-seekable forward-only streams. The stream is automatically closed when the table is disposed. ```APIDOC ## Table.Open (Stream) - Opening a dBASE Table from Stream ### Description Opens a dBASE table from any readable stream, including non-seekable forward-only streams. This is ideal for processing uploaded files in web applications or reading from network streams. The stream is automatically closed when the table is disposed. ### Method `Table.Open(Stream stream)` ### Endpoint N/A (Library method) ### Parameters #### Path Parameters - **stream** (Stream) - Required - The readable stream containing the .dbf file data. ### Request Example ```csharp using NDbfReader; using System.IO; using System.Net.Http; // Example: Reading from a MemoryStream byte[] dbfBytes = File.ReadAllBytes(@"C:\Data\products.dbf"); using (var stream = new MemoryStream(dbfBytes)) using (var table = Table.Open(stream)) { var reader = table.OpenReader(); while (reader.Read()) { Console.WriteLine(reader.GetString("PRODUCT_NAME")); } } // Example: ASP.NET file upload handling // [HttpPost] // public ActionResult Upload(HttpPostedFileBase file) // { // using (var table = Table.Open(file.InputStream)) // { // var reader = table.OpenReader(); // while (reader.Read()) // { // // Process uploaded DBF data // } // } // } ``` ### Response #### Success Response (Table Object) - **Table** (IDisposable) - An object representing the opened dBASE table, providing access to metadata and a reader. #### Response Example (See Request Example for usage) ``` -------------------------------- ### AsDataTable - Loading Entire Table into DataTable Source: https://context7.com/bloggerdude/ndbf/llms.txt Loads the entire dBASE table into an ADO.NET DataTable. This method is suitable when all rows and columns are needed in memory. It supports default UTF-8 encoding and custom encodings. ```APIDOC ## AsDataTable - Loading Entire Table into DataTable ### Description Extension method that loads the entire dBASE table into an ADO.NET DataTable. This is the simplest way to work with DBF data when you need all rows and columns in memory. ### Method `Table.Open(filePath).AsDataTable()` ### Parameters #### Path Parameters - **filePath** (string) - Required - The path to the DBF file. #### Query Parameters None #### Request Body None ### Request Example ```csharp using NDbfReader; using System.Data; using System.Text; using (var table = Table.Open(@"C:\Data\customers.dbf")) { DataTable dataTable = table.AsDataTable(); Console.WriteLine($"Loaded {dataTable.Rows.Count} rows"); } using (var table = Table.Open(@"C:\Data\legacy_data.dbf")) { DataTable dataTable = table.AsDataTable(Encoding.GetEncoding(1252)); Console.WriteLine($"Loaded {dataTable.Rows.Count} rows with encoding 1252"); } ``` ### Response #### Success Response (DataTable) - **DataTable** - An ADO.NET DataTable containing all rows and columns from the DBF file. #### Response Example ```csharp // Example of accessing data from the DataTable foreach (DataRow row in dataTable.Rows) { Console.WriteLine($"Customer: {row["NAME"]}, City: {row["CITY"]}"); } var filtered = dataTable.AsEnumerable() .Where(r => r.Field("COUNTRY") == "USA") .OrderBy(r => r.Field("NAME")); ``` ``` -------------------------------- ### Table.OpenReader Source: https://context7.com/bloggerdude/ndbf/llms.txt Opens a forward-only reader for iterating through table rows with optional encoding support. ```APIDOC ## Table.OpenReader ### Description Opens a forward-only reader for iterating through table rows. Only one reader can be open per table at a time. ### Parameters #### Method Parameters - **encoding** (Encoding) - Optional - The character encoding to use for decoding strings. Defaults to UTF-8. ### Response - **Reader** (Object) - A reader instance for iterating through the table. ``` -------------------------------- ### Load Specific Columns into DataTable with C# Source: https://context7.com/bloggerdude/ndbf/llms.txt Optimizes memory usage by loading only a subset of columns from the DBF file. ```csharp using NDbfReader; using System; using System.Data; using System.Text; using (var table = Table.Open(@"C:\Data\large_table.dbf")) { // Load only specific columns (default UTF-8 encoding) DataTable selectedData = table.AsDataTable("ID", "NAME", "EMAIL"); Console.WriteLine($"Columns loaded: {selectedData.Columns.Count}"); Console.WriteLine($"Rows loaded: {selectedData.Rows.Count}"); foreach (DataRow row in selectedData.Rows) { Console.WriteLine($"{row["ID"]}: {row["NAME"]} <{row["EMAIL"]}>"); } } // With custom encoding and selected columns using (var table = Table.Open(@"C:\Data\international.dbf")) { DataTable data = table.AsDataTable( Encoding.GetEncoding(1250), // Central European encoding "CUSTOMER_ID", "FULL_NAME", "ADDRESS", "PHONE" ); // Export to CSV or other format foreach (DataRow row in data.Rows) { Console.WriteLine(string.Join(",", row.ItemArray)); } } ``` -------------------------------- ### AsDataTable with Selected Columns Source: https://context7.com/bloggerdude/ndbf/llms.txt Loads only specified columns from the dBASE table into a DataTable. This improves performance and memory usage when only a subset of columns is required. Supports custom encodings. ```APIDOC ## AsDataTable with Selected Columns - Loading Specific Columns ### Description Loads only specified columns from the dBASE table into a DataTable. This improves performance and memory usage when you only need a subset of columns. ### Method `Table.Open(filePath).AsDataTable(encoding, columns)` or `Table.Open(filePath).AsDataTable(columns)` ### Parameters #### Path Parameters - **filePath** (string) - Required - The path to the DBF file. #### Query Parameters None #### Request Body None #### Method Overloads - `AsDataTable(params string[] columns)`: Loads specified columns with default UTF-8 encoding. - `AsDataTable(Encoding encoding, params string[] columns)`: Loads specified columns with a custom encoding. ### Request Example ```csharp using NDbfReader; using System.Data; using System.Text; // Load only specific columns (default UTF-8 encoding) using (var table = Table.Open(@"C:\Data\large_table.dbf")) { DataTable selectedData = table.AsDataTable("ID", "NAME", "EMAIL"); Console.WriteLine($"Columns loaded: {selectedData.Columns.Count}"); } // With custom encoding and selected columns using (var table = Table.Open(@"C:\Data\international.dbf")) { DataTable data = table.AsDataTable( Encoding.GetEncoding(1250), // Central European encoding "CUSTOMER_ID", "FULL_NAME", "ADDRESS", "PHONE" ); Console.WriteLine($"Rows loaded: {data.Rows.Count}"); } ``` ### Response #### Success Response (DataTable) - **DataTable** - An ADO.NET DataTable containing only the specified rows and columns from the DBF file. #### Response Example ```csharp // Example of accessing data from the DataTable foreach (DataRow row in selectedData.Rows) { Console.WriteLine($"{row["ID"]}: {row["NAME"]} <{row["EMAIL"]}>"); } // Export to CSV or other format foreach (DataRow row in data.Rows) { Console.WriteLine(string.Join(",", row.ItemArray)); } ``` ``` -------------------------------- ### Load DBF Table into DataTable Source: https://github.com/bloggerdude/ndbf/blob/master/README.md Converts the entire DBF table into a DataTable object for easier manipulation. Requires the table to be opened first. ```csharp using (var table = Table.Open("D:\\foo.dbf")) return table.AsDataTable(); ``` -------------------------------- ### Read Raw Column Bytes with Reader.GetBytes Source: https://context7.com/bloggerdude/ndbf/llms.txt Reads raw bytes of a column without interpretation, useful for unsupported types or custom binary data. Ensure a buffer of the correct size is provided. ```csharp using NDbfReader; using System; using (var table = Table.Open(@"C:\Data\binary_data.dbf")) { var reader = table.OpenReader(); // Get column info var binaryColumn = table.Columns["RAW_DATA"]; Console.WriteLine($"Column size: {binaryColumn.Size} bytes"); // Allocate buffer for raw bytes byte[] buffer = new byte[binaryColumn.Size]; while (reader.Read()) { string id = reader.GetString("ID"); // Read raw bytes into buffer reader.GetBytes(binaryColumn, buffer, 0); // Process raw bytes (example: convert to hex string) string hexString = BitConverter.ToString(buffer).Replace("-", ""); Console.WriteLine($"ID: {id}, Raw Data: {hexString}"); } } ``` -------------------------------- ### Reader.GetBytes Source: https://context7.com/bloggerdude/ndbf/llms.txt Reads the raw bytes of a column. ```APIDOC ## Reader.GetBytes ### Description Reads the raw bytes of a column without any interpretation or conversion. Useful for handling unsupported column types or custom binary data stored in dBASE fields. ### Parameters - **column** (Column) - Required - The column definition. - **buffer** (byte[]) - Required - The buffer to store the bytes. - **offset** (int) - Required - The offset in the buffer to start writing. ``` -------------------------------- ### Read Integer Values with Reader.GetInt32 Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves 32-bit integer values from Long type columns, suitable for binary integers. ```csharp using NDbfReader; using System; using (var table = Table.Open(@"C:\Data\inventory.dbf")) { var reader = table.OpenReader(); while (reader.Read()) { string sku = reader.GetString("SKU"); int quantity = reader.GetInt32("QTY_ON_HAND"); int reorderLevel = reader.GetInt32("REORDER_LVL"); if (quantity < reorderLevel) { Console.WriteLine($"WARNING: {sku} needs reorder. Current: {quantity}, Minimum: {reorderLevel}"); } } } ``` -------------------------------- ### Read Boolean Values with Reader.GetBoolean Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves nullable boolean values from logical columns. Handles T/F/Y/N and null values. ```csharp using NDbfReader; using System; using (var table = Table.Open(@"C:\Data\products.dbf")) { var reader = table.OpenReader(); int activeCount = 0; int discontinuedCount = 0; while (reader.Read()) { string productName = reader.GetString("NAME"); bool? isActive = reader.GetBoolean("ACTIVE"); bool? inStock = reader.GetBoolean("IN_STOCK"); if (isActive == true) { activeCount++; string stockStatus = inStock == true ? "In Stock" : "Out of Stock"; Console.WriteLine($"{productName}: Active - {stockStatus}"); } else { discontinuedCount++; } } Console.WriteLine($"Active products: {activeCount}"); Console.WriteLine($"Discontinued: {discontinuedCount}"); } ``` -------------------------------- ### Read String Column Values from DBF Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves string values from specified columns using either column name or column reference. The string is decoded using the encoding specified when opening the reader. ```csharp using NDbfReader; using System; using System.Text; using (var table = Table.Open(@"C:\Data\employees.dbf")) { var reader = table.OpenReader(Encoding.UTF8); // Get column reference for better performance in loops var nameColumn = table.Columns["NAME"]; var cityColumn = table.Columns["CITY"]; while (reader.Read()) { // Get string by column name string firstName = reader.GetString("FIRST_NAME"); string lastName = reader.GetString("LAST_NAME"); // Get string by column reference (more efficient for repeated access) string name = reader.GetString(nameColumn); string city = reader.GetString(cityColumn); Console.WriteLine($"Employee: {firstName} {lastName}, Location: {city}"); } } ``` -------------------------------- ### Read Column Values as Object with Reader.GetValue Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves column values as objects, useful for dynamic processing or unknown column types. The returned object type matches the column's CLR type. ```csharp using NDbfReader; using System; using (var table = Table.Open(@"C:\Data\dynamic_data.dbf")) { var reader = table.OpenReader(); // Print header foreach (var column in table.Columns) { Console.Write($"{column.Name}\t"); } Console.WriteLine(); // Print all rows dynamically while (reader.Read()) { foreach (var column in table.Columns) { // GetValue returns object - works with any column type object value = reader.GetValue(column); // Format based on actual type string formatted = value switch { null => "(null)", DateTime dt => dt.ToString("yyyy-MM-dd"), decimal d => d.ToString("F2"), bool b => b ? "Yes" : "No", _ => value.ToString() }; Console.Write($"{formatted}\t"); } Console.WriteLine(); } } ``` -------------------------------- ### Read Numeric Column Values (Decimal) from DBF Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves decimal values from numeric columns (Numeric or Float types). Returns a nullable decimal to handle null or empty values in the database. ```csharp using NDbfReader; using System; using (var table = Table.Open(@"C:\Data\sales.dbf")) { var reader = table.OpenReader(); decimal totalSales = 0; while (reader.Read()) { string product = reader.GetString("PRODUCT"); decimal? price = reader.GetDecimal("PRICE"); decimal? quantity = reader.GetDecimal("QUANTITY"); if (price.HasValue && quantity.HasValue) { decimal lineTotal = price.Value * quantity.Value; totalSales += lineTotal; Console.WriteLine($"{product}: {quantity} x ${price:F2} = ${lineTotal:F2}"); } } Console.WriteLine($"Total Sales: ${totalSales:F2}"); } ``` -------------------------------- ### Read Date Column Values from DBF Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves DateTime values from date columns. NDbfReader automatically parses dBASE's 8-character YYYYMMDD string format into DateTime objects. ```csharp using NDbfReader; using System; using (var table = Table.Open(@"C:\Data\orders.dbf")) { var reader = table.OpenReader(); while (reader.Read()) { string orderId = reader.GetString("ORDER_ID"); DateTime? orderDate = reader.GetDate("ORDER_DATE"); DateTime? shipDate = reader.GetDate("SHIP_DATE"); if (orderDate.HasValue) { Console.WriteLine($"Order {orderId}: Placed on {orderDate.Value:yyyy-MM-dd}"); if (shipDate.HasValue) { var daysToShip = (shipDate.Value - orderDate.Value).Days; Console.WriteLine($" Shipped after {daysToShip} days"); } else { Console.WriteLine(" Not yet shipped"); } } } } ``` -------------------------------- ### Read DBF from Non-Seekable Stream Source: https://github.com/bloggerdude/ndbf/blob/master/README.md Supports reading from non-seekable streams, such as HttpPostedFileBase.InputStream in ASP.NET applications. The table is opened directly from the provided stream. ```csharp [HttpPost] public ActionResult Upload(HttpPostedFileBase file) { using (var table = Table.Open(file.InputStream)) //.. } ``` -------------------------------- ### Reader.GetDate Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves a DateTime value from date columns. ```APIDOC ## Reader.GetDate ### Description Retrieves a DateTime value from date columns. Automatically parses the 8-character YYYYMMDD string format into a DateTime object. ### Parameters #### Method Parameters - **columnName** (string) - Required - The name of the date column. ### Response - **value** (DateTime?) - A nullable DateTime object. ``` -------------------------------- ### Reader.GetString Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves a string value from the specified column in the current row. ```APIDOC ## Reader.GetString ### Description Retrieves a string value from the specified column in the current row. The string is decoded using the encoding specified when opening the reader. ### Parameters #### Method Parameters - **columnNameOrReference** (string/Column) - Required - The name of the column or a column reference object. ### Response - **value** (string) - The string value stored in the column. ``` -------------------------------- ### Reader.GetInt32 Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves a 32-bit integer value from Long type columns. ```APIDOC ## Reader.GetInt32 ### Description Retrieves a 32-bit integer value from Long type columns. This is used for dBASE files that store binary integers (4 bytes) rather than numeric strings. ### Parameters - **columnName** (string) - Required - The name of the integer column to read. ### Response - **value** (int) - The 32-bit integer value. ``` -------------------------------- ### Reader.GetBoolean Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves a nullable boolean value from logical dBASE columns (T/F/Y/N). ```APIDOC ## Reader.GetBoolean ### Description Retrieves a boolean value from logical columns. dBASE logical fields store T/F/Y/N or space for null values. Returns a nullable boolean to handle null values. ### Parameters - **columnName** (string) - Required - The name of the logical column to read. ### Response - **value** (bool?) - The boolean value or null if the field is empty. ``` -------------------------------- ### Reader.GetDecimal Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves a decimal value from numeric or float columns. ```APIDOC ## Reader.GetDecimal ### Description Retrieves a decimal value from numeric columns (Numeric or Float types in dBASE). ### Parameters #### Method Parameters - **columnName** (string) - Required - The name of the numeric column. ### Response - **value** (decimal?) - A nullable decimal value to handle null or empty database entries. ``` -------------------------------- ### Reader.GetValue Source: https://context7.com/bloggerdude/ndbf/llms.txt Retrieves a column value as an object. ```APIDOC ## Reader.GetValue ### Description Retrieves a column value as an object, useful when the column type is not known at compile time or when processing columns dynamically. The returned object type matches the column's CLR type. ### Parameters - **column** (Column) - Required - The column definition object. ### Response - **value** (object) - The column value as an object. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.