In Web.Config
<connectionStrings>
<add name="connection" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=True;Initial Catalog=test;" providerName="System.Data.SqlClient" />
</connectionStrings>
In DBClass.cs this is the class file
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
//Get Connection String
public static string connectionstring = WebConfigurationManager.ConnectionStrings["connection"].ConnectionString;
//Get Connection
public static SqlConnection GetDbConnection()
{
return new SqlConnection(connectionstring);
}
In Your aspx.cs
SqlConnection con = DBClass.GetDbConnection();
SqlCommand cmd = new SqlCommand ("your sql command",con);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
<connectionStrings>
<add name="connection" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=True;Initial Catalog=test;" providerName="System.Data.SqlClient" />
</connectionStrings>
In DBClass.cs this is the class file
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
//Get Connection String
public static string connectionstring = WebConfigurationManager.ConnectionStrings["connection"].ConnectionString;
//Get Connection
public static SqlConnection GetDbConnection()
{
return new SqlConnection(connectionstring);
}
In Your aspx.cs
SqlConnection con = DBClass.GetDbConnection();
SqlCommand cmd = new SqlCommand ("your sql command",con);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
No comments:
Post a Comment