Creating SQL connection in ASP.NET C#

If you want to perform database operations from your ASP.NET website/application, Please use below code to connect and perform operations:


SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["<<YourConnectionStringKey>>"].ToString());
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter(); 
        cmd.Connection = con;
        cmd.CommandText = "<<Your Query Here>>"
 DataSet ds = new DataSet();
        da.Fill(ds);

Please share your queries…if any ?

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>