Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

Connecting to Database Express 2005 with VS 2005

1.27/5 (6 votes)
2 Aug 20061 min read 1  
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. <o:p>

<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"><v:f eqn="sum @0 1 0"><v:f eqn="sum 0 0 @1"><v:f eqn="prod @2 1 2"><v:f eqn="prod @3 21600 pixelWidth"><v:f eqn="prod @3 21600 pixelHeight"><v:f eqn="sum @0 0 1"><v:f eqn="prod @6 1 2"><v:f eqn="prod @7 21600 pixelWidth"><v:f eqn="sum @8 21600 0"><v:f eqn="prod @7 21600 pixelHeight"><v:f eqn="sum @10 21600 0"><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"><o:lock aspectratio="t" v:ext="edit"><o:p>

<o:p> 

<o:p> 

<v:shape id="_x0000_s1026" style="MARGIN-TOP: 1.15pt; Z-INDEX: -2; LEFT: 0px; MARGIN-LEFT: 9pt; WIDTH: 230.25pt; POSITION: absolute; HEIGHT: 179.25pt; TEXT-ALIGN: left" type="#_x0000_t75" wrapcoords="-70 0 -70 21510 21600 21510 21600 0 -70 0"><v:imagedata o:title="newdatabase" src="file:///C:\DOCUME~1\FEROCH~1\LOCALS~1\Temp\msohtml1\05\clip_image003.png"><w:wrap type="tight">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: <o:p>

<o:p> <o:p> 

<v:rect id="_x0000_s1027" style="MARGIN-TOP: 9pt; Z-INDEX: 2; LEFT: 0px; MARGIN-LEFT: 9pt; WIDTH: 423pt; POSITION: absolute; HEIGHT: 3in; TEXT-ALIGN: left"><o:p>

string connstring = "Data Source = .\\SQLEXPRESS; <o:p>

Initial Catalog = Practice_1; Integrated Security = True";<o:p>

<o:p> 

SqlConnection conn = new SqlConnection(connstring);<o:p>

SqlCommand comm = new SqlCommand();<o:p>

comm.Connection = conn;<o:p>

SqlDataAdapter myadapter = new SqlDataAdapter(comm);<o:p>

DataSet myset = new DataSet();<o:p>

<o:p> 

conn.Open();<o:p>

<o:p> 

comm.CommandText = "Select * From Checklist ";<o:p>

comm.ExecuteScalar();<o:p>

myadapter.Fill(myset, "Checklist");<o:p>

dataGridView1.DataSource = myset;<o:p>

dataGridView1.DataMember = "Checklist";<o:p>

           <o:p>

conn.Close();

 

The codes above must use “Using System.Data.SQLClient”.<o:p>

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here