如何使用C#.net和sqlExpress2008连接到Visual Studio 2010中的数据库 [英] How to connect to database in visual studio 2010 using C#.net with sqlExpress2008

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

问题描述

HI

i希望在Visual Studio 2010中使用数据库连接C#应用程序和

SQL Express2008,但我不知道如何连接,



请帮帮我

关心假货

解决方案

查看这些:



http:// csharp。 net-informations.com/data-providers/csharp-sql-server-connection.htm [ ^ ]



通过C#访问SQL Server的开发者指南 [ ^ ]



http://www.homeandlearn.co .uk / csharp / csharp_s12p3.html [ ^ ]



希望这会有所帮助:)



代码相关查询请点击这里!!

哎! Uday为您提供了一些很好的链接,足以知道如何连接SQL Server 2008,但如果您尝试使用向导将应用程序从Visual Studio 2010连接到SQL Server,则可以执行一些简单的步骤。看看

a)点击菜单中的工具菜单

b)点击连接到数据库,它将打开选择数据源对话框

c)从您系统上的所有已安装数据源中选择您的SQL Server 2008为Microsoft SQL Server

e)按继续按钮,之后它将为您提供放置您的服务器名称,用户ID的选项和密码

所以请以适当的方式遵循所有步骤。它可以轻松地将SQL Server 2008数据库连接到Visual Studio 2010应用程序。


 private void BindData()
{
try
{
string _connectionstring = @Data Source = .\SQLEXPRESS; Initial Catalog = Northwind; Integrated Security = True;
string _sql =SELECT * FROM [Order Details] WHERE OrderID< = 10250;
SqlConnection _connection = new SqlConnection(_connectionstring);
SqlCommand _command = new SqlCommand(_sql,_connection);
SqlDataAdapter _adapter = new SqlDataAdapter(_command);
DataTable _table = new DataTable();
_adapter.Fill(_table);

GridView1.DataSource = _table;
GridView1.DataBind();
}
抓住
{
throw;
}
}


HI
i want to connect the C# Application with database in visual studio 2010 with
SQL Express2008 , but i don't know how to connect,

please help me
Regards shams

解决方案

check these out:

http://csharp.net-informations.com/data-providers/csharp-sql-server-connection.htm[^]

Beginners guide to accessing SQL Server through C#[^]

http://www.homeandlearn.co.uk/csharp/csharp_s12p3.html[^]

hope this helps :)

for code related queries comment here!!


hey! Uday gives you some nice links which is enough to know how to connect SQL server 2008 but if you are trying to connect your Application from Visual Studio 2010 to SQL Server by using wizard then you can follow some simple steps. take a look
a) Click on Tools menu from menu
b) click on "Connect to Database" it will open "Choose Data Source" dialog
c) select your SQL server 2008 as "Microsoft SQL Server" out of all installed Data Source on your System
e) press Continue button, after that it will give you option to put your Server name,user ID and password
so follow all steps with as a appropriate way. it will easily connect SQL server 2008 databases to you Visual Studio 2010 application.


private void BindData()
{
    try
    {
        string _connectionstring = @"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";
        string _sql = "SELECT * FROM [Order Details] WHERE OrderID <= 10250";
        SqlConnection _connection = new SqlConnection(_connectionstring);
        SqlCommand _command = new SqlCommand(_sql,_connection);
        SqlDataAdapter _adapter = new SqlDataAdapter(_command);
        DataTable _table = new DataTable();
        _adapter.Fill(_table);

        GridView1.DataSource = _table;
        GridView1.DataBind();
    }
    catch
    {
        throw;
    }
}


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

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