Monday, 8 April 2013

How to make database connectivity in asp.net


hi, 
please add the follwoing code in you 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

No comments:

Post a Comment