如何创建一个简单的 Windows 窗体来访问 SQL Server 数据库?

发布于 2024-10-10 01:32:27 字数 548 浏览 0 评论 0原文

我相信这是一个非常新手的问题,如果我使用错误的论坛来提问,请指教。

我对 MS SQL Server 数据库以及 C++ 和 C# 编程有基本的了解。我正在尝试通过使用 MS SQL Server Express 2008 R2 设置自己的数据库并通过 C# Express 2010 创建的 Windows 表单访问它来自学更多。此时,我只想将其保留为免费或 Express 开发工具(但不一定是微软)。

无论如何,我使用此处提供的说明创建了一个数据库,并适当地设置了数据类型对于每一列(至少设置中没有错误)。

现在我正在使用 C# Express 设计 GUI,但在数据库连接方面却遇到了困难。

有没有一种简单的方法来访问我使用 C# Express 在本地创建的数据库?任何人都可以建议一个已阐明所有这些内容的指南吗?

我是一名自学者,因此我期待自学如何使用这些应用程序,但任何能让我朝着正确方向开始的指示将不胜感激。

I believe this is a very novice question, and if I'm using the wrong forum to ask, please advise.

I have a basic understanding of databasing with MS SQL Server, and programming with C++ and C#. I'm trying to teach myself more by setting up my own database with MS SQL Server Express 2008 R2 and accessing it via Windows forms created in C# Express 2010. At this point, I just want to keep it to free or Express dev tools (not necessarily Microsoft though).

Anyway, I created a database using the instructions provided here and I set the data types appropriately for each column (no errors in setup at least).

Now I'm designing the GUI in C# Express but I've kind of hit a wall as far as the database connection.

Is there a simple way to access the database I created locally using C# Express? Can anyone suggest a guide that has all this spelled out already?

I am a self-learner so I look forward to teaching myself how to use these applications, but any pointers to start me off in the right direction would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吐个泡泡 2024-10-17 01:32:27

我首先看一下本教程:

http://msdn.microsoft .com/en-us/library/ms178371.aspx

基本思想是创建一个 连接字符串将定义许多内容,包括:数据库服务器所在的位置、数据库名称是什么以及如何连接到它。

定义连接字符串后,您可能会使用 SqlConnection SqlCommandSqlDataReader 类用于与数据库的所有交互。如果您单击这三个类的链接并查看文档,您会发现它们有非常好的示例。

I'd start by taking a look at this tutorial:

http://msdn.microsoft.com/en-us/library/ms178371.aspx

The basic ideas is to create a connection string that will define a number of things, including: where your db server is, what the database name is, and how you are connecting to it.

Once you have your connection string defined you will probably use the SqlConnection, SqlCommand and SqlDataReader classes for all interactions with the database. If you click on the links for those three classes and look at the documentation you will see they have pretty good examples.

丢了幸福的猪 2024-10-17 01:32:27

如果您对 SQL 比 C# 更熟悉,您可能会想使用老式 ADO.NET。

ADO.NET 的 MSDN 介绍

You probably want to use old school ADO.NET if you are more comfortable in SQL than C#.

MSDN intro to ADO.NET

狼性发作 2024-10-17 01:32:27

毫无疑问,最简单的方法是使用 Visual Studio 中的 LINQ

您可能需要查看本教程,它将指导您完成所需的所有步骤。

http://www.codegod.de /WebAppCodeGod/tutorial-linq-to-sql---part-1-AID466.aspx

Far and away the easiest way to do this is with LINQ in Visual Studio

You might want to check out this tutorial which will guide you through all the steps you need.

http://www.codegod.de/WebAppCodeGod/tutorial-linq-to-sql---part-1-AID466.aspx

羁拥 2024-10-17 01:32:27

其简单

使用以下代码

SqlConnection con = 
 new SqlConnection(@"server=.\SQLEXPRESS;AttachDbFilename=path of database file;Integrated Security=True;User Instance=True");

its simple

use following code

SqlConnection con = 
 new SqlConnection(@"server=.\SQLEXPRESS;AttachDbFilename=path of database file;Integrated Security=True;User Instance=True");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文