国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

.NET中輕松應(yīng)用SQLite:零配置數(shù)據(jù)庫引擎的完美指南

這篇具有很好參考價值的文章主要介紹了.NET中輕松應(yīng)用SQLite:零配置數(shù)據(jù)庫引擎的完美指南。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

.NET中輕松應(yīng)用SQLite:零配置數(shù)據(jù)庫引擎的完美指南

?

SQLite 是一種輕量級的嵌入式數(shù)據(jù)庫引擎,它在 .NET 中被廣泛使用。SQLite 是一個零配置的數(shù)據(jù)庫引擎,不需要服務(wù)器,可以直接在應(yīng)用程序中使用。下面是一個簡單的示例,演示如何在 .NET 中使用 SQLite,并提供了常見的查詢、增加、修改和刪除功能。

首先,你需要在項目中安裝?System.Data.SQLite?包。你可以使用 NuGet 包管理器或通過 Package Manager Console 執(zhí)行以下命令:

Install-Package System.Data.SQLite

接下來,創(chuàng)建一個 C# 文件,例如?SQLiteExample.cs,并添加以下代碼:

using System;
using System.Data.SQLite;

class Program
{
    static void Main()
    {
        // 指定數(shù)據(jù)庫文件路徑
        string dbFilePath = "sample.db";

        // 連接字符串
        string connectionString = $"Data Source={dbFilePath};Version=3;";

        // 創(chuàng)建數(shù)據(jù)庫連接
        using (SQLiteConnection connection = new SQLiteConnection(connectionString))
        {
            connection.Open();

            // 創(chuàng)建表
            CreateTable(connection);

            // 插入數(shù)據(jù)
            InsertData(connection, "John Doe", 30);

            // 查詢數(shù)據(jù)
            QueryData(connection);

            // 更新數(shù)據(jù)
            UpdateData(connection, 1, "Updated Name", 35);

            // 查詢更新后的數(shù)據(jù)
            QueryData(connection);

            // 刪除數(shù)據(jù)
            DeleteData(connection, 1);

            // 查詢刪除后的數(shù)據(jù)
            QueryData(connection);
        }
    }

    static void CreateTable(SQLiteConnection connection)
    {
        using (SQLiteCommand command = new SQLiteCommand(
            "CREATE TABLE IF NOT EXISTS Users (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Age INTEGER);", connection))
        {
            command.ExecuteNonQuery();
        }

        Console.WriteLine("Table created or already exists.");
    }

    static void InsertData(SQLiteConnection connection, string name, int age)
    {
        using (SQLiteCommand command = new SQLiteCommand(
            "INSERT INTO Users (Name, Age) VALUES (@Name, @Age);", connection))
        {
            command.Parameters.AddWithValue("@Name", name);
            command.Parameters.AddWithValue("@Age", age);

            command.ExecuteNonQuery();
        }

        Console.WriteLine("Data inserted.");
    }

    static void QueryData(SQLiteConnection connection)
    {
        using (SQLiteCommand command = new SQLiteCommand(
            "SELECT * FROM Users;", connection))
        {
            using (SQLiteDataReader reader = command.ExecuteReader())
            {
                Console.WriteLine("Id\tName\tAge");
                while (reader.Read())
                {
                    Console.WriteLine($"{reader["Id"]}\t{reader["Name"]}\t{reader["Age"]}");
                }
            }
        }
        Console.WriteLine("Data queried.");
    }

    static void UpdateData(SQLiteConnection connection, int id, string name, int age)
    {
        using (SQLiteCommand command = new SQLiteCommand(
            "UPDATE Users SET Name=@Name, Age=@Age WHERE Id=@Id;", connection))
        {
            command.Parameters.AddWithValue("@Name", name);
            command.Parameters.AddWithValue("@Age", age);
            command.Parameters.AddWithValue("@Id", id);

            command.ExecuteNonQuery();
        }

        Console.WriteLine("Data updated.");
    }

    static void DeleteData(SQLiteConnection connection, int id)
    {
        using (SQLiteCommand command = new SQLiteCommand(
            "DELETE FROM Users WHERE Id=@Id;", connection))
        {
            command.Parameters.AddWithValue("@Id", id);

            command.ExecuteNonQuery();
        }

        Console.WriteLine("Data deleted.");
    }
}

請注意,上述示例假設(shè)你已經(jīng)安裝了?System.Data.SQLite?包,并且在項目目錄中創(chuàng)建了一個名為?sample.db?的 SQLite 數(shù)據(jù)庫文件。在實際應(yīng)用中,你需要根據(jù)自己的需求修改數(shù)據(jù)庫文件路徑和連接字符串。

這個示例演示了如何創(chuàng)建表、插入數(shù)據(jù)、查詢數(shù)據(jù)、更新數(shù)據(jù)和刪除數(shù)據(jù)。你可以根據(jù)具體的應(yīng)用場景和需求進行修改和擴展。

?

.NET中輕松應(yīng)用SQLite:零配置數(shù)據(jù)庫引擎的完美指南文章來源地址http://www.zghlxwxcb.cn/news/detail-787614.html

到了這里,關(guān)于.NET中輕松應(yīng)用SQLite:零配置數(shù)據(jù)庫引擎的完美指南的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 寶塔面板安裝配置MySQL,輕松管理數(shù)據(jù)庫【公網(wǎng)遠程訪問】

    寶塔面板安裝配置MySQL,輕松管理數(shù)據(jù)庫【公網(wǎng)遠程訪問】

    寶塔面板的簡易操作性,使得運維難度降低,簡化了Linux命令行進行繁瑣的配置,下面簡單幾步,通過寶塔面板+cpolar即可快速搭建一個mysql數(shù)據(jù)庫服務(wù)并且實現(xiàn)公網(wǎng)遠程訪問。 我們打開寶塔面板,點擊數(shù)據(jù)庫,然后點擊安裝mysql服務(wù), 選擇極速安裝即可,版本默認 然后等待安裝完成 安裝

    2024年02月05日
    瀏覽(94)
  • .net core .net6 讀取數(shù)據(jù)庫 讀取配置文件 保姆級教程

    .net core .net6 讀取數(shù)據(jù)庫 讀取配置文件 保姆級教程

    本文環(huán)境 Microsoft Visual Studio 2022 .Net6 SQLServer2019 在解決方案管理器右鍵添加相關(guān)的包,如下兩個包 Microsoft.Data.SqlClient SQLServer SQLServer數(shù)據(jù)庫 Microsoft.Extensions.Configuration.Json json配置文件 添加配置文件 appsettings.json,選始終復(fù)制 添加json配置文件內(nèi)容如下 DefaultConnection 根據(jù)自己的

    2024年02月08日
    瀏覽(25)
  • SQLite Studio 連接 SQLite數(shù)據(jù)庫

    SQLite Studio 連接 SQLite數(shù)據(jù)庫

    1.1、按WIN+R,打開控制臺,然后把指引到我們的SQLite的安裝路徑,輸入D:,切換到D盤,cd 地址,切換到具體文件夾,輸入“sqlite3”,啟動服務(wù) 1.2、創(chuàng)建數(shù)據(jù)庫和表 ?id和name是表的屬性(列名),int和varchar是列名的數(shù)據(jù)類型,int表示是整型,varchar表示是字符串,長度是20,p

    2024年02月15日
    瀏覽(25)
  • SQLite數(shù)據(jù)庫

    SQLite數(shù)據(jù)庫

    目錄 SQLite數(shù)據(jù)庫 在Android中的使用 SQLiteOpenHelper中的方法 增刪改查 添加數(shù)據(jù) insert() 查詢數(shù)據(jù) query(),rawQuery() 查詢和添加案例 數(shù)據(jù)庫幫助類: MainActivity: Activity_main.xml: ????????SQLite是一個 輕量級的嵌入數(shù)據(jù)庫 ,實現(xiàn)了自給自足的、 無服務(wù)器 的、 零配置 的、事務(wù)性的

    2023年04月15日
    瀏覽(31)
  • 數(shù)據(jù)庫開發(fā)(Sqlite)

    數(shù)據(jù)庫開發(fā)(Sqlite)

    1、數(shù)據(jù)庫開發(fā) 1.1 數(shù)據(jù)與數(shù)據(jù)管理 什么是信息? ??信息是指對現(xiàn)實世界存在方式或運動狀態(tài)的反應(yīng)。 什么是數(shù)據(jù)? ??數(shù)據(jù)是指存儲在某一媒體上,能夠被識別的物理符號; ??數(shù)據(jù)的概念在數(shù)據(jù)處理領(lǐng)域已經(jīng)被大為拓寬,不僅包括字符組成的文本形式的數(shù)據(jù),而且還

    2023年04月16日
    瀏覽(20)
  • Android studio 連接SQLite數(shù)據(jù)庫 +創(chuàng)建數(shù)據(jù)庫+創(chuàng)建數(shù)據(jù)庫表

    Android studio 連接SQLite數(shù)據(jù)庫 +創(chuàng)建數(shù)據(jù)庫+創(chuàng)建數(shù)據(jù)庫表

    Android studio 之數(shù)據(jù)庫的使用 連接創(chuàng)建SQLite 大家好,歡迎來到寒依。 相信看啦我的教程 當老師問你在學(xué)習(xí)Android studio 數(shù)據(jù)庫使用過程中遇到什么困難,分享一下你的感悟和解決方法 的時候,你可以直接大膽的說出來: “老師我沒有遇到問題,看啦寒依的教程 暢行無阻” 我

    2024年02月02日
    瀏覽(35)
  • 用idea查看sqlite數(shù)據(jù)庫idea sqlite

    用idea查看sqlite數(shù)據(jù)庫idea sqlite

    ? ? ? ? ? ? ? ? ? ? 在此做個筆記

    2024年02月10日
    瀏覽(25)
  • sqlite數(shù)據(jù)庫基本使用

    sqlite數(shù)據(jù)庫是sql數(shù)據(jù)庫引擎的一種,它不需要任何配置,不需要服務(wù)器,是一個輕量級的嵌入式數(shù)據(jù)庫。安裝sqlite見文檔:SQLite3的安裝與使用_sqlite3安裝_冒險的夢想家的博客-CSDN博客 下面直接對sqlite3數(shù)據(jù)庫基本命令進行說明: 1.獲取sqlite版本的命令 sqlite3 --version 2.數(shù)據(jù)庫創(chuàng)

    2024年02月10日
    瀏覽(32)
  • 數(shù)據(jù)庫--Sqlite3

    數(shù)據(jù)庫--Sqlite3

    ?1、思維導(dǎo)圖 ?2sqlite3在linux中是實現(xiàn)數(shù)據(jù)的增刪,改 #includemyhead.h int main(int argc, const char *argv[]) { ? ? ? ? //1、定義一個數(shù)據(jù)庫句柄指針 ? ? ? ? sqlite3* ppDb =NULL; ? ? ? ? //2、創(chuàng)建或打開數(shù)據(jù)庫 ? ? ? ? if(sqlite3_open(\\\"./mydb.db\\\",ppDb)!=SQLITE_OK) ? ? ? ? { ? ? ? ? ? ? ? ? printf(

    2024年04月27日
    瀏覽(27)
  • SQLite數(shù)據(jù)庫實現(xiàn)數(shù)據(jù)增刪改查

    SQLite數(shù)據(jù)庫實現(xiàn)數(shù)據(jù)增刪改查

    當前文章介紹的設(shè)計的主要功能是利用 SQLite 數(shù)據(jù)庫實現(xiàn)寵物投喂器上傳數(shù)據(jù)的存儲,并且支持數(shù)據(jù)的增刪改查操作。其中,寵物投喂器上傳的數(shù)據(jù)包括投喂間隔時間、水溫、剩余重量等參數(shù)。 實現(xiàn)功能: 創(chuàng)建 SQLite 數(shù)據(jù)庫表,用于存儲寵物投喂器上傳的數(shù)據(jù)。 實現(xiàn)對數(shù)據(jù)庫

    2024年02月12日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包