Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted

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.
 
Share this answer
 
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;
    }
}
 
Share this answer
 
Comments
Salvi Shahzad 15-Nov-16 4:26am    
I used this code and added my database connection string but got some errors
1313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313

3333333333333333333333333333333333333333333333333333333333333
33333333333333333333333333333333333333333333333333333333
131313131111111111111111111111111111111111113111111111111111111111311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111113111111111111111111111111111111111111111111111111111111311333313131313333333333333333333333313333333333333333333333131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131313131133333333333333333333333333
 
Share this answer
 
http://csharp-sqlconnection.blogspot.in/ visit this for easy and short code for database access
 
Share this answer
 
Comments
CHill60 19-Nov-13 18:35pm    
Very badly formatted blog I'm afraid, and doesn't really add to the solutions posted 2 years ago

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900