.NET幫助 DuckDB C#(對開發者如何理解的工作) Jacob Mellor 更新:2026年1月18日 下載 IronPDF NuGet 下載 DLL 下載 Windows Installer 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 DuckDB.NET 是一個開源的 .NET 綁定 DuckDB 原生程式庫的提供者,旨在與 C# 無縫整合。 它提供了 ADO.NET 提供者,使您可以在 .NET 應用程式中輕鬆使用 DuckDB,這是一個底層綁定程式庫。 此軟體包非常適合希望在 C# 環境中利用 DuckDB 強大分析功能的開發者。 安裝 安裝 DuckDB.NET 是很簡單的。 您可以使用 .NET CLI 將其添加到您的專案: dotnet add package DuckDB.NET.Data.Full dotnet add package DuckDB.NET.Data.Full SHELL 或者,您可以通過 Visual Studio中的NuGet Package Manager 安裝它。 基本使用 安裝完成後,您可以開始使用 DuckDB.NET 在您的 C# 應用程式中執行 SQL 查詢。 這是個簡單的範例: using System; using DuckDB.NET.Data; class Program { static void Main() { // Create and open a connection to an in-memory DuckDB database using var duckdbconnection = new DuckDBConnection("Data Source=:memory:"); duckdbconnection.Open(); // Create a command associated with the connection using var command = duckdbconnection.CreateCommand(); // Create a table named 'integers' command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);"; command.ExecuteNonQuery(); // Insert some data into the 'integers' table command.CommandText = "INSERT INTO integers VALUES (3, 4), (5, 6), (7, 8);"; command.ExecuteNonQuery(); // Retrieve the count of rows in the 'integers' table command.CommandText = "SELECT count(*) FROM integers"; var executeScalar = command.ExecuteScalar(); // Select all values from the 'integers' table command.CommandText = "SELECT foo, bar FROM integers;"; // Execute the query and process the results 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() { // Create and open a connection to an in-memory DuckDB database using var duckdbconnection = new DuckDBConnection("Data Source=:memory:"); duckdbconnection.Open(); // Create a command associated with the connection using var command = duckdbconnection.CreateCommand(); // Create a table named 'integers' command.CommandText = "CREATE TABLE integers(foo INTEGER, bar INTEGER);"; command.ExecuteNonQuery(); // Insert some data into the 'integers' table command.CommandText = "INSERT INTO integers VALUES (3, 4), (5, 6), (7, 8);"; command.ExecuteNonQuery(); // Retrieve the count of rows in the 'integers' table command.CommandText = "SELECT count(*) FROM integers"; var executeScalar = command.ExecuteScalar(); // Select all values from the 'integers' table command.CommandText = "SELECT foo, bar FROM integers;"; // Execute the query and process the results using var reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine($"{reader.GetInt32(0)}, {reader.GetInt32(1)}"); } } } $vbLabelText $csharpLabel 此範例展示了如何創建一個表,插入數據,並使用 DuckDB.NET 查詢數據。 輸出 數據讀入 DuckDB.NET 支援從各種格式讀取數據,包括 CSV 和 Parquet 檔案。 以下是如何從 CSV 檔案讀取數據: command.CommandText = "COPY integers FROM 'example.csv' (FORMAT CSV);"; command.ExecuteNonQuery(); command.CommandText = "COPY integers FROM 'example.csv' (FORMAT CSV);"; command.ExecuteNonQuery(); $vbLabelText $csharpLabel 與資料框的整合 DuckDB.NET 還可以與資料框進行整合,允許您使用熟悉的 SQL 語法操作數據。 這對於數據分析任務特別有用。 結果轉換 您可以將查詢結果轉換為各種格式,如清單或自定義對象,這樣您就可以輕鬆地在應用程式中使用數據: var results = new List<(int foo, int bar)>(); // Read and store results to a List while (reader.Read()) { results.Add((reader.GetInt32(0), reader.GetInt32(1))); // You can also use a loop with an index to iterate the results } var results = new List<(int foo, int bar)>(); // Read and store results to a List while (reader.Read()) { results.Add((reader.GetInt32(0), reader.GetInt32(1))); // You can also use a loop with an index to iterate the results } $vbLabelText $csharpLabel 寫入數據到磁碟 DuckDB.NET 支援以多種格式將數據寫入磁碟。 您可以使用 COPY 語句將數據匯出到 CSV 檔案: command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);"; command.ExecuteNonQuery(); command.CommandText = "COPY integers TO 'output.csv' (FORMAT CSV);"; command.ExecuteNonQuery(); $vbLabelText $csharpLabel IronPDF 簡介 IronPDF 是一個 C# PDF 程式庫,允許在 .NET 專案中生成、管理和提取 PDF 文檔的內容。 以下是一些主要功能: IronPDF 是一個方便的工具,可以讓您將網頁、網址及 HTML 轉換為 PDF。 最棒的部分? PDF 文件看起來就像原始網頁一樣 - 保持所有格式和樣式。 因此,如果您需要從線上生成 PDF,像是報告或發票,IronPDF 是您的首選。 using IronPdf; class Program { static void Main(string[] args) { var renderer = new ChromePdfRenderer(); // 1. Convert HTML String to PDF var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"; var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent); pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf"); // 2. Convert HTML File to PDF var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath); pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf"); // 3. Convert URL to PDF var url = "http://ironpdf.com"; // Specify the URL var pdfFromUrl = renderer.RenderUrlAsPdf(url); pdfFromUrl.SaveAs("URLToPDF.pdf"); } } using IronPdf; class Program { static void Main(string[] args) { var renderer = new ChromePdfRenderer(); // 1. Convert HTML String to PDF var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"; var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent); pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf"); // 2. Convert HTML File to PDF var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath); pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf"); // 3. Convert URL to PDF var url = "http://ironpdf.com"; // Specify the URL var pdfFromUrl = renderer.RenderUrlAsPdf(url); pdfFromUrl.SaveAs("URLToPDF.pdf"); } } $vbLabelText $csharpLabel HTML 至 PDF 轉換: 將 HTML、CSS 和 JavaScript 內容轉換為 PDF 文件。 使用 Chrome 渲染引擎生成像素級完美的 PDF 文件。 從 URL、HTML 檔案或 HTML 字串生成 PDF。 圖片和內容轉換: 將圖片轉換為 PDF 文件或從 PDF 文件中提取圖片。 從現有的 PDF 文件中提取文本和圖片。 支援各種圖像格式,如 JPG、PNG 等。 編輯和操控: 設定 PDF 文件的屬性、安全性和許可權。 向 PDF 文件添加數位簽章。 編輯元數據及修訂歷史。 跨平台支援: 適用於 .NET Core (8、7、6、5 和 3.1+),.NET Standard (2.0+),以及 .NET Framework (4.6.2+)。 相容於 Windows、Linux 和 macOS。 可在 NuGet 上找到,方便安裝。 使用 IronPDF 和 DuckDB .NET 生成 PDF 文件 首先,使用 Visual Studio 創建一個主控台應用程式,如下所示。 提供專案名稱。 提供 .NET 版本。 安裝 IronPDF 軟體包。 安裝 DuckDB.NET 軟體包。 using DuckDB.NET.Data; using IronPdf; 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>"; // Create and open a connection to an in-memory DuckDB database using var connection = new DuckDBConnection("Data Source=:memory:"); connection.Open(); using var command = connection.CreateCommand(); // Create a table named 'integers' command.CommandText = "CREATE TABLE integers(book STRING, cost INTEGER);"; command.ExecuteNonQuery(); content += "<p>CREATE TABLE integers(book STRING, cost INTEGER);</p>"; // Insert some data into the 'integers' table 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>"; // Select all values from the 'integers' table command.CommandText = "SELECT book, cost FROM integers;"; using var reader = command.ExecuteReader(); content += "<p>SELECT book, cost FROM integers;</p>"; // Execute the query and process the results, appending them to the HTML content while (reader.Read()) { content += $"<p>{reader.GetString(0)}, {reader.GetInt32(1)}</p>"; Console.WriteLine($"{reader.GetString(0)}, {reader.GetInt32(1)}"); } // Save data to CSV 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(); // Generate and save PDF var pdf = renderer.RenderHtmlAsPdf(content); pdf.SaveAs("AwesomeDuckDbNet.pdf"); } } } using DuckDB.NET.Data; using IronPdf; 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>"; // Create and open a connection to an in-memory DuckDB database using var connection = new DuckDBConnection("Data Source=:memory:"); connection.Open(); using var command = connection.CreateCommand(); // Create a table named 'integers' command.CommandText = "CREATE TABLE integers(book STRING, cost INTEGER);"; command.ExecuteNonQuery(); content += "<p>CREATE TABLE integers(book STRING, cost INTEGER);</p>"; // Insert some data into the 'integers' table 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>"; // Select all values from the 'integers' table command.CommandText = "SELECT book, cost FROM integers;"; using var reader = command.ExecuteReader(); content += "<p>SELECT book, cost FROM integers;</p>"; // Execute the query and process the results, appending them to the HTML content while (reader.Read()) { content += $"<p>{reader.GetString(0)}, {reader.GetInt32(1)}</p>"; Console.WriteLine($"{reader.GetString(0)}, {reader.GetInt32(1)}"); } // Save data to CSV 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(); // Generate and save PDF var pdf = renderer.RenderHtmlAsPdf(content); pdf.SaveAs("AwesomeDuckDbNet.pdf"); } } } $vbLabelText $csharpLabel 程式碼說明 這段程式碼旨在展示如何使用 DuckDB.NET 進行資料庫操作,並使用 IronPDF 生成包含資料庫查詢結果的 PDF 報告。 主要組成部分 DuckDB.NET: DuckDBConnection: 建立與內存中的 DuckDB 資料庫檔案("Data Source=:memory:")的連接。 此連接在整個程式碼中用於執行 SQL 命令。 資料庫操作: 表創建: 定義一個 SQL 命令(CREATE TABLE integers(book STRING, cost INTEGER);)用於創建一個名為 integers 的表,包含欄位 book (STRING) 和 cost (INTEGER)。 數據插入: 向 integers 表中插入行(INSERT INTO integers VALUES ('book1', 25), ('book2', 30), ('book3', 10);)。 數據檢索: 執行一個 SELECT 查詢(SELECT book, cost FROM integers;)以從 integers 表中獲取數據。 檢索到的數據格式化為 HTML(內容)並打印到控制台。 使用 IronPDF 生成 PDF: 將 HTML 渲染為 PDF: 使用 IronPDF 的 ChromePdfRenderer 將 HTML 內容(content)轉換為 PDF 文件(pdf)。 保存 PDF: 將生成的 PDF 保存為 "AwesomeDuckDbNet.pdf",位於當前目錄中。 輸出 PDF IronPDF 授權 IronPDF 軟體包需要授權才能運行。 在應用程式開始時,在訪問軟體包之前添加以下程式碼。 IronPdf.License.LicenseKey = "IRONPDF-KEY"; IronPdf.License.LicenseKey = "IRONPDF-KEY"; $vbLabelText $csharpLabel 可以在 IronPDF 的試用授權頁面 上獲得試用授權。 結論 DuckDB.NET C# 軟體包是一個強大的工具,用於將 DuckDB 的分析功能整合到 .NET 應用程式中。 其易用性、對多種數據格式的支援,以及與 C# 的無縫整合,使其成為開發者在處理數據密集型應用程式時的絕佳選擇。 無論您是構建數據分析工具、ETL 管道,還是其他數據驅動的應用程式,DuckDB.NET 都能幫助您有效地達成目標。 常見問題解答 DuckDB.NET 在 C# 應用程式中有什麼用途? DuckDB.NET 用於整合 DuckDB 原生庫至 C# 應用程式中,透過 ADO.NET 提供強大的分析能力給開發者。 如何在 C# 專案中安裝 DuckDB.NET? 您可以透過 .NET CLI 命令 dotnet add package DuckDB.NET.Data.Full 或在 Visual Studio 中透過 NuGet 套件管理員安裝 DuckDB.NET。 如何使用 DuckDB.NET 執行 SQL 查詢? 您可以建立與 DuckDBConnection 的連線,並執行 SQL 命令來建立表格、插入及檢索資料。 DuckDB.NET 能支援從 CSV 和 Parquet 檔案讀取資料嗎? 是的,DuckDB.NET 支援從包括 CSV 和 Parquet 檔案在內的多種格式進行資料攝取,允許在 C# 應用程式中無縫整合和操作這些資料類型。 怎樣在 C# 中將 HTML 轉換為 PDF? 您可以使用 IronPDF 的 RenderHtmlAsPdf 方法將 HTML 字符串轉換為 PDF。您還可以使用 RenderHtmlFileAsPdf 將 HTML 文件轉換為 PDF。 使用 DuckDB.NET 在資料密集的專案中有哪些優點? DuckDB.NET 提供強大的分析能力,支援基於 SQL 的資料操作,並能與 C# 應用程式輕鬆整合,對於資料密集的專案極為理想。 DuckDB.NET 如何與資料框架整合? DuckDB.NET 可以與資料框架整合,支持基於 SQL 的資料操作,這對於執行複雜的資料分析任務特別有用。 如何使用 DuckDB.NET 將資料匯出為 CSV 檔案? 您可以使用 COPY 語句將資料匯出為 CSV 檔案。例如,使用 COPY integers TO 'output.csv' (FORMAT CSV); 將表格資料匯出為 CSV 檔案。 IronPDF 支持哪些平台? IronPDF 支援 .NET Core (8, 7, 6, 5 和 3.1+)、.NET Standard (2.0+)和 .NET Framework (4.6.2+),並且與 Windows、Linux 和 macOS 相容。 我可以結合 DuckDB.NET 和 IronPDF 來生成報告嗎? 是的,您可以將 DuckDB.NET 用於資料庫操作,將 IronPDF 用於生成 PDF 報告,利用 DuckDB 的資料庫功能結合 IronPDF 的 PDF 生成特性。 Jacob Mellor 立即與工程團隊聊天 首席技術官 Jacob Mellor是Iron Software的首席技術官,也是開創C# PDF技術的前瞻性工程師。作為Iron Software核心代碼庫的原始開發者,他自公司成立以來就塑造了公司的產品架構,並與CEO Cameron Rimington將公司轉型為服務NASA、Tesla以及全球政府機構的50多人公司。Jacob擁有曼徹斯特大學土木工程一級榮譽學士學位(1998年–2001年)。他於1999年在倫敦開立首家軟體公司,並於2005年建立了他的第一個.NET組件,專注於解決Microsoft生態系統中的複雜問題。他的旗艦作品IronPDF和Iron Suite .NET程式庫全球已獲得超過3000萬次NuGet安裝,他的基礎代碼不斷在全球各地驅動開發者工具。擁有25年以上的商業經驗和41年的編碼專業知識,Jacob仍然專注於推動企業級C#、Java和Python PDF技術的創新,同時指導下一代技術領導者。 相關文章 更新2026年2月20日 銜接 CLI 簡化與 .NET : 使用 Curl DotNet 與 IronPDF for .NET Jacob Mellor 藉由 CurlDotNet 彌補了這方面的不足,CurlDotNet 是為了讓 .NET 生態系統能熟悉 cURL 而建立的函式庫。 閱讀更多 更新2025年12月20日 RandomNumberGenerator C# 使用RandomNumberGenerator C#類可以幫助將您的PDF生成和編輯項目提升至新水準 閱讀更多 更新2025年12月20日 C#字符串等於(它如何對開發者起作用) 當結合使用強大的PDF庫IronPDF時,開關模式匹配可以讓您構建更智能、更清晰的邏輯來進行文檔處理 閱讀更多 LazyCache C#(對開發者如何理解的工作)WebGrease .NET Core(對開發者...
更新2026年2月20日 銜接 CLI 簡化與 .NET : 使用 Curl DotNet 與 IronPDF for .NET Jacob Mellor 藉由 CurlDotNet 彌補了這方面的不足,CurlDotNet 是為了讓 .NET 生態系統能熟悉 cURL 而建立的函式庫。 閱讀更多