我如何在C#中使用SQL [英] How do I work with SQL in C#

查看:77
本文介绍了我如何在C#中使用SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿!

我实际上打算用C#创建一个电话方向。我知道SQL的基础知识。

大多数书籍使用Northwind数据库或任何其他数据库解释ADO.NET。

我的问题是如何创建自己的数据库和用我的代码创建连接?

我的数据库最初会变得简单。

谢谢。

Hey!
I'm actually planning to create a Phone Direction in C#. I know the basics of SQL.
Most of the books explain ADO.NET using Northwind database or any other database.
My question is how can I create my own database and create a connection with my code?
My Database is going to simple initially.
Thank you.

推荐答案

假设您使用的是SQL Server,可以采用以下两种方式之一:

1)在Visual Studio中创建数据库: http://msdn.microsoft.com/en-us/library/ms233763.aspx [ ^ ]

2)在SQL Server Management Studio中创建数据库: http://msdn.microsoft.com/en-us/library/ms186312.aspx [ ^ ]



还有其他方法,但这些都很简单。



但首先,请坐下来仔细考虑你的数据库以及表格和数据它应该包含:此阶段的错误可能会让您后来感到非常悲伤!
Assuming you are using SQL Server, you can do it in one of two ways:
1) Create a database in Visual Studio: http://msdn.microsoft.com/en-us/library/ms233763.aspx[^]
2) Create a database in SQL Server Management Studio: http://msdn.microsoft.com/en-us/library/ms186312.aspx[^]

There are other ways, but those are the easy ones.

But first, please sit down and think very carefully about your DB and what tables and data it should contain: an error at this stage can cause you a lot of grief later on!


您正在使用哪个版本的Visual Studio,DataBox下的工具箱中有SQLDataSource组件,其中只需点击几下即可连接到所需的数据库。



您可以进一步使用此SQL数据源进行工作。



其他方法是在配置文件中创建与所需SQL DB的连接,如下所示



< add name = ReportConnectionprovidername =System.Data.SqlClientconnectionstring =Datasource =ServerName; Initialcatalog =DBName; Userid =username; Password = password; connectiontimeout =100000000; />< brmode =hold>

你也可以定义它后面的代码。
Which version of visual studio you are using , there is SQLDataSource component in Toolbox under Data Tab, Which can connect to the desired database in just few clicks.

and you can use the this SQL data source further for your work.

The other ways is to create the connection to the required SQL DB as given below in your config file

<add name=""ReportConnection"" providername=""System.Data.SqlClient"" connectionstring=""Data" source="ServerName;Initial" catalog="DBName;User" id="username;Password=password;connection" timeout="100000000;"/><br" mode="hold">
You can also define it you code behind.


这篇关于我如何在C#中使用SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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