Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
DuckDB.NET is an open-source provider of .NET bindings for the DuckDB native library, designed to integrate seamlessly with C#. It provides an ADO.NET provider, making it easy to use DuckDB, a low-level bindings library, within .NET applications. This package is ideal for developers looking to leverage DuckDB’s powerful analytical capabilities in a C# environment.
Installing DuckDB.NET is straightforward. You can add it to your project using the .NET CLI:
dotnet add package DuckDB.NET.Data.Full
dotnet add package DuckDB.NET.Data.Full
IRON VB CONVERTER ERROR developers@ironsoftware.com
Alternatively, you can install it via the NuGet Package Manager in Visual Studio.
Once installed, you can start using DuckDB.NET to execute SQL queries within your C# application. Here’s a simple example:
using System;
using DuckDB.NET.Data;
class Program
{
static void Main()
{
using var duckdbconnection = new DuckDBConnection("Data Source=:memory:");
duckdbconnection.Open();
using var command = duckdbconnection.CreateCommand();
command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO integers VALUES (3, 4), (5, 6), (7, 8);";
command.ExecuteNonQuery();
command.CommandText = "Select count(*) from integers";
var executeScalar = command.ExecuteScalar();
command.CommandText = "SELECT foo, bar FROM integers;";
using var reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine($"{reader.GetInt32(0)}, {reader.GetInt32(1)}");
}
}
}
using System;
using DuckDB.NET.Data;
class Program
{
static void Main()
{
using var duckdbconnection = new DuckDBConnection("Data Source=:memory:");
duckdbconnection.Open();
using var command = duckdbconnection.CreateCommand();
command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO integers VALUES (3, 4), (5, 6), (7, 8);";
command.ExecuteNonQuery();
command.CommandText = "Select count(*) from integers";
var executeScalar = command.ExecuteScalar();
command.CommandText = "SELECT foo, bar FROM integers;";
using var reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine($"{reader.GetInt32(0)}, {reader.GetInt32(1)}");
}
}
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
This example demonstrates how to create a table, insert data, and query the data using DuckDB.NET.
DuckDB.NET supports reading data from various formats, including CSV and Parquet files. Here’s how you can read data from a CSV file:
command.CommandText = "COPY integers FROM 'example.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
command.CommandText = "COPY integers FROM 'example.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
IRON VB CONVERTER ERROR developers@ironsoftware.com
DuckDB.NET can also integrate with data frames, allowing you to manipulate data using familiar SQL syntax. This is particularly useful for data analysis tasks.
You can convert query results to various formats, such as lists or custom objects, making it easy to work with the data in your application:
var results = new List<(int foo, int bar)>();
while (reader.Read())
{
results.Add((reader.GetInt32(0), reader.GetInt32(1)));
// can also use for with var index and iterate the results
}
var results = new List<(int foo, int bar)>();
while (reader.Read())
{
results.Add((reader.GetInt32(0), reader.GetInt32(1)));
// can also use for with var index and iterate the results
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
DuckDB.NET supports writing data to disk in various formats. You can use the COPY statement to export data to a CSV file:
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
IRON VB CONVERTER ERROR developers@ironsoftware.com
IronPDF is a C# PDF library that allows to generate, manage, and extract content from PDF documents in .NET projects. Here are some key features:
HTML to PDF Conversion:
Convert HTML, CSS, and JavaScript content to PDFs.
Image and Content Conversion:
Convert images to and from PDF docs.
Editing and Manipulation:
Set properties, security, and permissions for PDF docs.
Cross-Platform Support:
Works with .NET Core (8, 7, 6, 5, and 3.1+), .NET Standard (2.0+), and .NET Framework (4.6.2+).
To start with, create a Console application using Visual Studio as below.
Provide the Project name.
Provide .NET Version.
Install the IronPDF package.
Install the DuckDB.NET package.
using DuckDB.NET.Data;
namespace CodeSample
{
public static class DuckDbDemo
{
public static void Execute()
{
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
var content = "<h1>Demo DuckDb and IronPDF</h1>";
content += "<h2>Create DuckDBConnection</h2>";
content += "<p>new DuckDBConnection(\"Data Source=:memory:\");</p>";
content += "<p></p>";
using var connection = new DuckDBConnection("Data Source=:memory:");
connection.Open();
using var command = connection.CreateCommand();
command.CommandText = "CREATE TABLE integers(book STRING, cost INTEGER);";
command.ExecuteNonQuery();
content += "<p>CREATE TABLE integers(book STRING, cost INTEGER);</p>";
command.CommandText = "INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);";
command.ExecuteNonQuery();
content += "<p>INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);</p>";
command.CommandText = "SELECT book, cost FROM integers;";
using var reader = command.ExecuteReader();
content += "<p>SELECT book, cost FROM integers;</p>";
while (reader.Read())
{
content += $"<p>{reader.GetString(0)}, {reader.GetInt32(1)}</p>";
Console.WriteLine($"{reader.GetString(0)}, {reader.GetInt32(1)}");
}
content += "<p>Save data to CSV with COPY integers TO 'output.csv' (FORMAT CSV);</p>";
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
var pdf = renderer.RenderHtmlAsPdf(content);
// Export to a file or Stream
pdf.SaveAs("AwesomeDuckDbNet.pdf");
}
}
}
using DuckDB.NET.Data;
namespace CodeSample
{
public static class DuckDbDemo
{
public static void Execute()
{
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
var content = "<h1>Demo DuckDb and IronPDF</h1>";
content += "<h2>Create DuckDBConnection</h2>";
content += "<p>new DuckDBConnection(\"Data Source=:memory:\");</p>";
content += "<p></p>";
using var connection = new DuckDBConnection("Data Source=:memory:");
connection.Open();
using var command = connection.CreateCommand();
command.CommandText = "CREATE TABLE integers(book STRING, cost INTEGER);";
command.ExecuteNonQuery();
content += "<p>CREATE TABLE integers(book STRING, cost INTEGER);</p>";
command.CommandText = "INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);";
command.ExecuteNonQuery();
content += "<p>INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);</p>";
command.CommandText = "SELECT book, cost FROM integers;";
using var reader = command.ExecuteReader();
content += "<p>SELECT book, cost FROM integers;</p>";
while (reader.Read())
{
content += $"<p>{reader.GetString(0)}, {reader.GetInt32(1)}</p>";
Console.WriteLine($"{reader.GetString(0)}, {reader.GetInt32(1)}");
}
content += "<p>Save data to CSV with COPY integers TO 'output.csv' (FORMAT CSV);</p>";
command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);";
command.ExecuteNonQuery();
var pdf = renderer.RenderHtmlAsPdf(content);
// Export to a file or Stream
pdf.SaveAs("AwesomeDuckDbNet.pdf");
}
}
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
The code aims to showcase how to use DuckDB.NET for database operations and IronPDF for generating a PDF report containing the database query results.
DuckDB.NET:
Database Operations:
Table Creation: Defines a SQL command (CREATE TABLE integers(book STRING, cost INTEGER);) to create a table named integers with columns book (STRING) and var column cost (INTEGER).
PDF Generation with IronPDF:
The IronPDF package requires a license to run. Add the below code at the start of the application before the package is accessed.
IronPdf.License.LicenseKey = "IRONPDF-KEY";
IronPdf.License.LicenseKey = "IRONPDF-KEY";
IRON VB CONVERTER ERROR developers@ironsoftware.com
A trial License is available here.
The DuckDB.NET C# package is a powerful tool for integrating DuckDB’s analytical capabilities into .NET applications. Its ease of use, support for various data formats, and seamless integration with C# make it an excellent choice for developers working on data-intensive applications. Whether you are building data analysis tools, ETL pipelines, or other data-driven applications, DuckDB.NET can help you achieve your goals efficiently.
9 .NET API products for your office documents