{"id":147345,"date":"2024-11-01T12:41:26","date_gmt":"2024-11-01T04:41:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/147345\/"},"modified":"2024-11-01T12:41:27","modified_gmt":"2024-11-01T04:41:27","slug":"winform%e6%87%89%e7%94%a8%e7%a8%8b%e5%ba%8f%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e6%9c%ac%e5%9c%b0%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-winform%e6%9c%ac%e5%9c%b0%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/147345\/","title":{"rendered":"WinForm\u61c9\u7528\u7a0b\u5e8f\u5982\u4f55\u4f7f\u7528\u672c\u5730\u6578\u64da\u5eab\uff1f (winform\u672c\u5730\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"winform%e6%87%89%e7%94%a8%e7%a8%8b%e5%ba%8f%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e6%9c%ac%e5%9c%b0%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-mieaEsWpmL\">WinForm\u61c9\u7528\u7a0b\u5e8f\u5982\u4f55\u4f7f\u7528\u672c\u5730\u6578\u64da\u5eab\uff1f<\/h1>\n<p>\u5728\u73fe\u4eca\u7684\u61c9\u7528\u7a0b\u5e8f\u958b\u767c\u4e2d\uff0cWinForm\u61c9\u7528\u7a0b\u5e8f\u56e0\u5176\u76f4\u89c0\u7684\u7528\u6236\u754c\u9762\u548c\u6613\u65bc\u4f7f\u7528\u7684\u7279\u6027\u800c\u53d7\u5230\u5ee3\u6cdb\u6b61\u8fce\u3002\u7576\u958b\u767c\u8005\u9700\u8981\u5728\u61c9\u7528\u7a0b\u5e8f\u4e2d\u5b58\u5132\u548c\u7ba1\u7406\u6578\u64da\u6642\uff0c\u4f7f\u7528\u672c\u5730\u6578\u64da\u5eab\u662f\u4e00\u500b\u5e38\u898b\u7684\u9078\u64c7\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728WinForm\u61c9\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u672c\u5730\u6578\u64da\u5eab\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e6%9c%ac%e5%9c%b0%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e9%81%b8%e6%93%87-mieaEsWpmL\">\u672c\u5730\u6578\u64da\u5eab\u7684\u9078\u64c7<\/h2>\n<p>\u5728WinForm\u61c9\u7528\u7a0b\u5e8f\u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u9078\u64c7\u591a\u7a2e\u672c\u5730\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u3002\u6700\u5e38\u898b\u7684\u9078\u64c7\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>SQLite\uff1a<\/strong>\u4e00\u500b\u8f15\u91cf\u7d1a\u7684\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff0c\u9069\u5408\u5c0f\u578b\u61c9\u7528\u7a0b\u5e8f\u548c\u55ae\u7528\u6236\u74b0\u5883\u3002<\/li>\n<li><strong>SQL Server Compact\uff1a<\/strong>\u5fae\u578b\u7248\u7684SQL Server\uff0c\u9069\u5408\u684c\u9762\u61c9\u7528\u7a0b\u5e8f\u3002<\/li>\n<li><strong>Access\uff1a<\/strong>Microsoft Access\u6578\u64da\u5eab\uff0c\u9069\u5408\u5c0f\u578b\u6578\u64da\u7ba1\u7406\u9700\u6c42\u3002<\/li>\n<\/ul>\n<p>\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u91cd\u9ede\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528SQLite\u4f5c\u70ba\u672c\u5730\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e8%a8%ad%e7%bd%aesqlite%e6%95%b8%e6%93%9a%e5%ba%ab-mieaEsWpmL\">\u8a2d\u7f6eSQLite\u6578\u64da\u5eab<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728\u60a8\u7684WinForm\u9805\u76ee\u4e2d\u6dfb\u52a0SQLite\u7684\u652f\u6301\u3002\u53ef\u4ee5\u901a\u904eNuGet\u5305\u7ba1\u7406\u5668\u5b89\u88ddSQLite\u7684\u76f8\u95dc\u5eab\u3002\u4ee5\u4e0b\u662f\u5b89\u88ddSQLite\u7684\u6b65\u9a5f\uff1a<\/p>\n<pre><code>Install-Package System.Data.SQLite<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u958b\u59cb\u5275\u5efa\u548c\u64cd\u4f5cSQLite\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e8%a1%a8-mieaEsWpmL\">\u5275\u5efa\u6578\u64da\u5eab\u548c\u8868<\/h2>\n<p>\u4ee5\u4e0b\u662f\u5275\u5efaSQLite\u6578\u64da\u5eab\u548c\u8868\u7684\u793a\u4f8b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>\nusing System.Data.SQLite;\n\n\/\/ \u5275\u5efa\u6578\u64da\u5eab\nSQLiteConnection.CreateFile(\"MyDatabase.sqlite\");\n\n\/\/ \u9023\u63a5\u5230\u6578\u64da\u5eab\nusing (SQLiteConnection connection = new SQLiteConnection(\"Data Source=MyDatabase.sqlite;Version=3;\"))\n{\n    connection.Open();\n\n    \/\/ \u5275\u5efa\u8868\n    string sql = \"CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)\";\n    SQLiteCommand command = new SQLiteCommand(sql, connection);\n    command.ExecuteNonQuery();\n}\n<\/code><\/pre>\n<h2 id=\"%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-mieaEsWpmL\">\u63d2\u5165\u6578\u64da<\/h2>\n<p>\u5275\u5efa\u8868\u5f8c\uff0c\u60a8\u53ef\u4ee5\u63d2\u5165\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u63d2\u5165\u6578\u64da\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\nusing (SQLiteConnection connection = new SQLiteConnection(\"Data Source=MyDatabase.sqlite;Version=3;\"))\n{\n    connection.Open();\n\n    string sql = \"INSERT INTO users (name, age) VALUES ('John Doe', 30)\";\n    SQLiteCommand command = new SQLiteCommand(sql, connection);\n    command.ExecuteNonQuery();\n}\n<\/code><\/pre>\n<h2 id=\"%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-mieaEsWpmL\">\u67e5\u8a62\u6578\u64da<\/h2>\n<p>\u63d2\u5165\u6578\u64da\u5f8c\uff0c\u60a8\u53ef\u4ee5\u67e5\u8a62\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u67e5\u8a62\u6578\u64da\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\nusing (SQLiteConnection connection = new SQLiteConnection(\"Data Source=MyDatabase.sqlite;Version=3;\"))\n{\n    connection.Open();\n\n    string sql = \"SELECT * FROM users\";\n    SQLiteCommand command = new SQLiteCommand(sql, connection);\n    SQLiteDataReader reader = command.ExecuteReader();\n\n    while (reader.Read())\n    {\n        Console.WriteLine(\"ID: \" + reader[\"id\"] + \", Name: \" + reader[\"name\"] + \", Age: \" + reader[\"age\"]);\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e6%9b%b4%e6%96%b0%e5%92%8c%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-mieaEsWpmL\">\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da<\/h2>\n<p>\u9664\u4e86\u63d2\u5165\u548c\u67e5\u8a62\u6578\u64da\uff0c\u60a8\u9084\u53ef\u4ee5\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\n\/\/ \u66f4\u65b0\u6578\u64da\nusing (SQLiteConnection connection = new SQLiteConnection(\"Data Source=MyDatabase.sqlite;Version=3;\"))\n{\n    connection.Open();\n\n    string sql = \"UPDATE users SET age = 31 WHERE name = 'John Doe'\";\n    SQLiteCommand command = new SQLiteCommand(sql, connection);\n    command.ExecuteNonQuery();\n}\n\n\/\/ \u522a\u9664\u6578\u64da\nusing (SQLiteConnection connection = new SQLiteConnection(\"Data Source=MyDatabase.sqlite;Version=3;\"))\n{\n    connection.Open();\n\n    string sql = \"DELETE FROM users WHERE name = 'John Doe'\";\n    SQLiteCommand command = new SQLiteCommand(sql, connection);\n    command.ExecuteNonQuery();\n}\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-mieaEsWpmL\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528\u672c\u5730\u6578\u64da\u5eab\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8WinForm\u61c9\u7528\u7a0b\u5e8f\u7684\u6578\u64da\u7ba1\u7406\u80fd\u529b\u3002\u901a\u904eSQLite\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5275\u5efa\u3001\u8b80\u53d6\u3001\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da\u3002\u9019\u4e9b\u57fa\u672c\u64cd\u4f5c\u70ba\u958b\u767c\u66f4\u8907\u96dc\u7684\u61c9\u7528\u7a0b\u5e8f\u5960\u5b9a\u4e86\u57fa\u790e\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e\u6211\u5011\u7684<a href=\"https:\/\/server.hk\">VPS<\/a> \u670d\u52d9\uff0c\u63d0\u4f9b\u7a69\u5b9a\u7684\u6578\u64da\u5b58\u5132\u548c\u7ba1\u7406\u74b0\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728WinForm\u61c9\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u672c\u5730\u6578\u64da\u5eab\uff0c\u5be6\u73fe\u6578\u64da\u5b58\u5132\u3001\u67e5\u8a62\u548c\u7ba1\u7406\u7684\u9ad8\u6548\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-147345","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/147345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=147345"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/147345\/revisions"}],"predecessor-version":[{"id":147346,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/147345\/revisions\/147346"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=147345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=147345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=147345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}