65.9K
CodeProject is changing. Read more.
Home

Connecting to Database Express 2005 with VS 2005

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.27/5 (6 votes)

Aug 2, 2006

1 min read

viewsIcon

25592

Codes to help to connect VS 2005 to SQL Express manualy

Introduction

After install Visual Studio 2005, you must install “SQL Server Management Studio Express CTP”. This program plugs into SQL Express 2005. Run SQL Server Management Studio Express CTP and press connect to connect into Server Management Studio Express.

 

 

After connect, you must make a new database and a new table, for example:

make database and give a name for a new database “Practice_1”.

Then, make one table which consist of field “No” and field “Name” and give name for a new table “Checklist”.

After finish making your table, please input same data into your table. Now run your Visual Studio 2005 and make new application windows.  Drag dataGridView into your design form and choose dock in properties become fill. Double click your form and insert these codes:

  

string connstring = "Data Source = .\\SQLEXPRESS;

Initial Catalog = Practice_1; Integrated Security = True";

 

SqlConnection conn = new SqlConnection(connstring);

SqlCommand comm = new SqlCommand();

comm.Connection = conn;

SqlDataAdapter myadapter = new SqlDataAdapter(comm);

DataSet myset = new DataSet();

 

conn.Open();

 

comm.CommandText = "Select * From Checklist ";

comm.ExecuteScalar();

myadapter.Fill(myset, "Checklist");

dataGridView1.DataSource = myset;

dataGridView1.DataMember = "Checklist";

          

conn.Close();

 

The codes above must use “Using System.Data.SQLClient”.

Start Debugging your program and at your dataGridView will come up data which you have filled when making of Database.