How to Connect SQL Server to C#

0
97

connectionSQLoutPutPI connect SQL Server

 

This time, I will teach you how to connect SQL Server 2005 to C# using Microsoft Visual Studio 2008. With this, you can create a connection between C#.net and SQL Server 2005 database.

 

Let’s begin:

 

First, open Visual Studio 2008 and create a new project.

connectionSQLFig1

 

The window of “New Project” will appear. In the New Project window, select “Visual C#” and create a new Windows Form Application.

connectionSQLFig2

 

Do the form just like this.

connectionSQLFig3

Now, double click a button and do the following codes for the connection between SQL Server and Visual C#.

Note: Put using System.Data.SqlClient; above the namespace to access sql server library.

 

Output:

connectionSQLoutPutPI

 

You can do this following example:

Reminder: You must put your database file(testdb.mdf) inside the bin folder of your project to make this second example work.

Output:

connectionSQLoutPutPI

 

For all students who need programmer for your thesis system or anyone who needs a sourcecode in any programming languages. You can contact me @ :
Email – [email protected]
Mobile No. – 09305235027 – tnt

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here