hi all! Till now i have made simple applications in C# that dont make use of Database. But now i wanna make a simple projects that keep records of employee i.e. their name,ids,emails,addresses etc. For that purpose i need database connectivy code in C#. Another problem is this that i m using visual studio 2005 and i dont have SQL server 2000 or later. The only thing i have is SQl server 7.0. Can anybody tell me how i connect my application with SQL server 7.0.

Gaurav,

Its been awhile since I worked with SQL7, but it doesn't matter, they are almost all the same, except for the connection string.
The easiest way to find out what the connection string should be is to use Visual Studio's
Data menu then Add New Data Source... option.
Select Database, then click the New Connection... button.
When the dialog comes up, select to change the datasource (it defaults to Microsoft Sql Server). Select the <other> option, and select the OLE DB provider. This will bring you back to the former dialog. Now you can drop down the Combobox, and locate the Microsoft OLE DB provider for SQL Server. Fill out the rest of the info like the database server, database, user authentication, etc. and test the connection.

Once you get a good connection, press ok, and you get back to the first dialog.
Now, you can either let Visual Studio create a full blown class for this data source that will manage the server by pressing next (pick you name and objects), or you can just get the connection string from the bottom of the dialog, and copy/paste that into your code after pressing cancel.

Provider=SQLOLEDB.1;Data Source=SHAWHP;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind

Now add the Data and OLE namespaces to your code:

using System.Data;
using System.Data.OleDb;

Now you can get your connection working by first instantiating a connection.

OleDbConnection conn = new OleDbConnection("Provider=SQLOLEDB.1;Data Source=SHAWHP;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind");

Hopefully you know that you can get SQL2005 Express for free from the Microsoft web site. It also came on the install disk for VS2005

Hope this helps,
Jerry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.