Define All Module level variables
SqlDataAdapter Da;
SqlConnection Con;
SqlCommand Cmd;
DataSet ds;
Note: add the connection string in web config file in website-
<connectionStrings>
<add name="ConnectionString" connectionString="data source=MANISH-PC\SQLEXPRESS;database=Demo;uid=sa;pwd=server"
providerName="System.Data.SqlClient" />
</connectionStrings>
private void OpenConnection()
{
if (Con == null)
{
Con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
}
// lets open the connection
if (Con.State == ConnectionState.Closed)
{
Con.Open();
}
Cmd = new SqlCommand();
//Set active connection with the command object
Cmd.Connection = Con;
}
private void CloseConnection()
{
if (Con.State == ConnectionState.Open)
{
Con.Close();
}
}
/// <summary>
/// This is to release the memory from the connection object
/// </summary>
private void DisposeConnection()
{
if (Con != null)
{
Con.Dispose();
Con = null;
}
}
SqlDataAdapter Da;
SqlConnection Con;
SqlCommand Cmd;
DataSet ds;
Note: add the connection string in web config file in website-
<connectionStrings>
<add name="ConnectionString" connectionString="data source=MANISH-PC\SQLEXPRESS;database=Demo;uid=sa;pwd=server"
providerName="System.Data.SqlClient" />
</connectionStrings>
private void OpenConnection()
{
if (Con == null)
{
Con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
}
// lets open the connection
if (Con.State == ConnectionState.Closed)
{
Con.Open();
}
Cmd = new SqlCommand();
//Set active connection with the command object
Cmd.Connection = Con;
}
private void CloseConnection()
{
if (Con.State == ConnectionState.Open)
{
Con.Close();
}
}
/// <summary>
/// This is to release the memory from the connection object
/// </summary>
private void DisposeConnection()
{
if (Con != null)
{
Con.Dispose();
Con = null;
}
}
No comments:
Post a Comment