{"id":145887,"date":"2024-11-01T11:05:29","date_gmt":"2024-11-01T03:05:29","guid":{"rendered":"https:\/\/server.hk\/cnblog\/145887\/"},"modified":"2024-11-01T11:05:30","modified_gmt":"2024-11-01T03:05:30","slug":"vs2023-%e8%bc%95%e9%ac%86%e8%aa%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e9%81%8e%e7%a8%8b%ef%bc%8c%e5%af%a6%e7%8f%be%e9%ab%98%e6%95%88%e6%95%b8%e6%93%9a%e6%93%8d%e4%bd%9c-vs2023-%e8%aa%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/145887\/","title":{"rendered":"VS2023 \u8f15\u9b06\u8abf\u7528\u6578\u64da\u5eab\u904e\u7a0b\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u64cd\u4f5c (vs2023 \u8abf\u7528\u6578\u64da\u5eab\u904e\u7a0b)"},"content":{"rendered":"<h1 id=\"vs2023-%e8%bc%95%e9%ac%86%e8%aa%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e9%81%8e%e7%a8%8b%ef%bc%8c%e5%af%a6%e7%8f%be%e9%ab%98%e6%95%88%e6%95%b8%e6%93%9a%e6%93%8d%e4%bd%9c-WnQyYVHrCk\">VS2023 \u8f15\u9b06\u8abf\u7528\u6578\u64da\u5eab\u904e\u7a0b\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u64cd\u4f5c<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u8edf\u4ef6\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u5df2\u6210\u70ba\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u61c9\u7528\u9084\u662f\u5927\u578b\u4f01\u696d\u7cfb\u7d71\uff0c\u6578\u64da\u5eab\u90fd\u626e\u6f14\u8457\u95dc\u9375\u89d2\u8272\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\uff0c\u958b\u767c\u8005\u9700\u8981\u66f4\u9ad8\u6548\u3001\u66f4\u7c21\u55ae\u7684\u65b9\u5f0f\u4f86\u8abf\u7528\u6578\u64da\u5eab\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728 Visual Studio 2023 (VS2023) \u4e2d\u8f15\u9b06\u8abf\u7528\u6578\u64da\u5eab\uff0c\u5be6\u73fe\u9ad8\u6548\u7684\u6578\u64da\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"1-%e7%92%b0%e5%a2%83%e8%a8%ad%e7%bd%ae-WnQyYVHrCk\">1. \u74b0\u5883\u8a2d\u7f6e<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fdd\u4f60\u7684\u958b\u767c\u74b0\u5883\u5df2\u7d93\u8a2d\u7f6e\u59a5\u7576\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u5b89\u88dd Visual Studio 2023\u3002<\/li>\n<li>\u78ba\u4fdd\u5df2\u5b89\u88dd .NET \u6846\u67b6\u548c\u76f8\u61c9\u7684\u6578\u64da\u5eab\u9a45\u52d5\u7a0b\u5e8f\uff08\u5982 SQL Server\u3001MySQL \u7b49\uff09\u3002<\/li>\n<li>\u5275\u5efa\u4e00\u500b\u65b0\u7684\u9805\u76ee\uff0c\u9078\u64c7\u9069\u5408\u7684\u61c9\u7528\u985e\u578b\uff08\u5982 ASP.NET Core\u3001Windows Forms \u7b49\uff09\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab-WnQyYVHrCk\">2. \u9023\u63a5\u6578\u64da\u5eab<\/h2>\n<p>\u5728 VS2023 \u4e2d\uff0c\u9023\u63a5\u6578\u64da\u5eab\u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 C# \u9023\u63a5 SQL Server \u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<pre><code>using System;\nusing System.Data.SqlClient;\n\nclass Program\n{\n    static void Main()\n    {\n        string connectionString = \"Server=your_server;Database=your_database;User Id=your_username;Password=your_password;\";\n        \n        using (SqlConnection connection = new SqlConnection(connectionString))\n        {\n            connection.Open();\n            Console.WriteLine(\"\u6578\u64da\u5eab\u9023\u63a5\u6210\u529f\uff01\");\n        }\n    }\n}<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u78bc\u4e2d\uff0c\u8acb\u6839\u64da\u5be6\u969b\u60c5\u6cc1\u66ff\u63db\u9023\u63a5\u5b57\u7b26\u4e32\u4e2d\u7684\u53c3\u6578\u3002\u4f7f\u7528 <code>using<\/code> \u8a9e\u53e5\u53ef\u4ee5\u78ba\u4fdd\u5728\u4f7f\u7528\u5b8c\u9023\u63a5\u5f8c\u81ea\u52d5\u91cb\u653e\u8cc7\u6e90\u3002<\/p>\n<h2 id=\"3-%e5%9f%b7%e8%a1%8c%e6%95%b8%e6%93%9a%e6%93%8d%e4%bd%9c-WnQyYVHrCk\">3. \u57f7\u884c\u6578\u64da\u64cd\u4f5c<\/h2>\n<p>\u4e00\u65e6\u6210\u529f\u9023\u63a5\u5230\u6578\u64da\u5eab\uff0c\u5c31\u53ef\u4ee5\u9032\u884c\u5404\u7a2e\u6578\u64da\u64cd\u4f5c\uff0c\u5982\u67e5\u8a62\u3001\u63d2\u5165\u3001\u66f4\u65b0\u548c\u522a\u9664\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"3-1-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-WnQyYVHrCk\">3.1 \u67e5\u8a62\u6578\u64da<\/h3>\n<pre><code>string query = \"SELECT * FROM your_table\";\nusing (SqlCommand command = new SqlCommand(query, connection))\n{\n    using (SqlDataReader reader = command.ExecuteReader())\n    {\n        while (reader.Read())\n        {\n            Console.WriteLine(reader[\"column_name\"].ToString());\n        }\n    }\n}<\/code><\/pre>\n<h3 id=\"3-2-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-WnQyYVHrCk\">3.2 \u63d2\u5165\u6578\u64da<\/h3>\n<pre><code>string insertQuery = \"INSERT INTO your_table (column1, column2) VALUES (@value1, @value2)\";\nusing (SqlCommand command = new SqlCommand(insertQuery, connection))\n{\n    command.Parameters.AddWithValue(\"@value1\", \"data1\");\n    command.Parameters.AddWithValue(\"@value2\", \"data2\");\n    command.ExecuteNonQuery();\n}<\/code><\/pre>\n<h3 id=\"3-3-%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-WnQyYVHrCk\">3.3 \u66f4\u65b0\u6578\u64da<\/h3>\n<pre><code>string updateQuery = \"UPDATE your_table SET column1 = @value WHERE column2 = @condition\";\nusing (SqlCommand command = new SqlCommand(updateQuery, connection))\n{\n    command.Parameters.AddWithValue(\"@value\", \"new_data\");\n    command.Parameters.AddWithValue(\"@condition\", \"condition_value\");\n    command.ExecuteNonQuery();\n}<\/code><\/pre>\n<h3 id=\"3-4-%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-WnQyYVHrCk\">3.4 \u522a\u9664\u6578\u64da<\/h3>\n<pre><code>string deleteQuery = \"DELETE FROM your_table WHERE column_name = @condition\";\nusing (SqlCommand command = new SqlCommand(deleteQuery, connection))\n{\n    command.Parameters.AddWithValue(\"@condition\", \"value_to_delete\");\n    command.ExecuteNonQuery();\n}<\/code><\/pre>\n<h2 id=\"4-%e9%8c%af%e8%aa%a4%e8%99%95%e7%90%86-WnQyYVHrCk\">4. \u932f\u8aa4\u8655\u7406<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u6642\uff0c\u932f\u8aa4\u8655\u7406\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u53ef\u4ee5\u4f7f\u7528 <code>try-catch<\/code> \u584a\u4f86\u6355\u7372\u4e26\u8655\u7406\u7570\u5e38\uff1a<\/p>\n<pre><code>try\n{\n    \/\/ \u6578\u64da\u5eab\u64cd\u4f5c\u4ee3\u78bc\n}\ncatch (SqlException ex)\n{\n    Console.WriteLine(\"\u6578\u64da\u5eab\u932f\u8aa4: \" + ex.Message);\n}\ncatch (Exception ex)\n{\n    Console.WriteLine(\"\u5176\u4ed6\u932f\u8aa4: \" + ex.Message);\n}<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-WnQyYVHrCk\">\u7e3d\u7d50<\/h2>\n<p>\u5728 VS2023 \u4e2d\u8abf\u7528\u6578\u64da\u5eab\u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\uff0c\u901a\u904e\u6b63\u78ba\u7684\u74b0\u5883\u8a2d\u7f6e\u548c\u4ee3\u78bc\u5be6\u73fe\uff0c\u53ef\u4ee5\u8f15\u9b06\u9032\u884c\u9ad8\u6548\u7684\u6578\u64da\u64cd\u4f5c\u3002\u7121\u8ad6\u662f\u67e5\u8a62\u3001\u63d2\u5165\u3001\u66f4\u65b0\u9084\u662f\u522a\u9664\uff0c\u958b\u767c\u8005\u90fd\u53ef\u4ee5\u5229\u7528 C# \u63d0\u4f9b\u7684\u5f37\u5927\u529f\u80fd\u4f86\u5be6\u73fe\u9700\u6c42\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4e5f\u662f\u81f3\u95dc\u91cd\u8981\u7684\uff0c\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22VS2023\u8f15\u9b06\u8abf\u7528\u6578\u64da\u5eab\u7684\u904e\u7a0b\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u64cd\u4f5c\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\u8207\u6578\u64da\u7ba1\u7406\u80fd\u529b\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-145887","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/145887","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=145887"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/145887\/revisions"}],"predecessor-version":[{"id":145888,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/145887\/revisions\/145888"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=145887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=145887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=145887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}