使用C#语言的C#数据库和Visual Studio数据库 [英] Database for C# and database for visual studio using C# language

查看:250
本文介绍了使用C#语言的C#数据库和Visual Studio数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一些问题,对不起,如果我问错了问题,但是我只想知道我们如何使用Visual Studio和数据库连接C#编程,以及C#编程实际使用的数据库是什么?如果我问错了问题

谢谢您的好意

I have some questions here,i''m sorry if I ask the wrong questions,but I just want to know how do we connect the C# programming using Visual Studio and the database and what is the actually database used by C# programming if i''m asking the wrong questions

thank you for your kindness

推荐答案

以相反的顺序回答您的问题:
"C#编程实际使用的数据库是什么"

就您的意思而言,没有一个.尽管您可以使用任何具有有效连接且具有适当类的数据库,但是您不必在程序中使用任何形式的数据库. Visual Studio本身会保留一些数据库信息来帮助您处理代码,这些信息存储在SQL数据库中.

我们如何使用Visual Studio和数据库连接C#编程"

有多种方法,可以创建一个Connection和一个Command,然后使用Reader,或者可以将DataAdapter和DataTables与DataBinding一起使用.

更简单的方法可能是使用Connection和Command:
To answer your questions in reverse order:
"what is the actually database used by C# programming"

There isn''t one, in the sense you mean. You do not have to use a database of any form in your program, although you can use any you have a valid connection to and the appropriate classes. Visual Studio itself does keep some database information to help it with processing your code, and this is stored in an SQL database.

"how do we connect the C# programming using Visual Studio and the database"

There are a number of ways, you can create a Connection, and a Command, and then use a Reader, or you could use a DataAdapter and DataTables with DataBinding.

The easier way to do it is probably with a Connection and a Command:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT iD, description FROM myTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            while (reader.Read())
                {
                int id = (int) reader["iD"];
                string desc = (string) reader["description"];
                Console.WriteLine("ID: {0}\n    {1}", iD, desc);
                }
            }
        }
    }

要计算连接字符串,请尝试使用服务器资源管理器"窗格在VS中建立连接:
1)打开服务器资源管理器.
2)右键单击数据连接",然后选择添加连接"
3)在随后的对话框中,选择您的数据源和数据库,指定安全信息,然后按测试连接"按钮.
4)连接正常后,按确定"
5)在服务器资源管理器"窗格中突出显示您的数据库,然后查看属性"窗格.将显示一个连接字符串的工作示例,您可以将其复制并粘贴到您的应用程序或配置文件中.

To work out the connection string, try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.


这篇关于使用C#语言的C#数据库和Visual Studio数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆