How to make database connectivity in asp.net?

Solved/Closed
Digvijaysinh Posts 10 Registration date Tuesday January 27, 2009 Status Member Last seen July 6, 2009 - Updated on Jan 31, 2019 at 03:02 PM
 ARVIND - Apr 2, 2018 at 05:23 AM
Hello,

I am looking for the database connectivity in asp.net with sql server 2005 or NS Access 2007.

Can anyone help me?

Thanks in advance!
System Configuration: Windows XP Microsoft visual studio 2008,C#.
Related:

16 responses

Hi,

Please add the following code in your
aspx.cs
page:

Step 1: Add Namspace using System.Data.SqlClient;

Step 2: Make Sql connection.

Write this code to create Sql connection:
SqlConnection con = new SqlConnection("Server=You server name or comp name;Database=Yourdatabasename;Trusted_Connectopn=True");
SqlCommand cmd = new SqlCommand("Write your sql query here eg. select * from Table name");
con.Open();
DataSet ds = new DataSet(cmd,con);
SqlDataAdapter da = new SqlDataAdapter();
da.Fill(ds);
con.Close();


I hope this should work.

Thanks!
376
Hello

in a aspx.cs file I write connection string like
System.Data.SqlClient;
SqlConnection conn = new SqlConnection("Data Source=SYS014\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");

but it is showing error at SYS014\ELLE message is unrecorgnized escape sequence. how to rectify that and how can I connect to database
0
sachith > av_deepu
Jun 17, 2009 at 02:33 AM
Hi,

I think your problem is with the "/" character.

SqlConnection conn = new SqlConnection("Data Source=SYS014\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");

In the above line you use either @ sign in front like this

SqlConnection conn = new SqlConnection(@"Data Source=SYS014\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");

or

use the '/' sign twice like this.

SqlConnection conn = new SqlConnection("Data Source=SYS014\\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");

Hope this will solve your problem
0