Hi
It is better and easy to use a separate class for the database operations. For Example.
protected void Page_Load(object sender, EventArgs e)
{
dbConnection connection = new dbConnection();
private void FetchContactMail()
{
string contactEmail = string.Empty;
object myData = connection.FetchMyData("select CONTACT_EMAIL from QAFranchise.HDR_CONTACT_LIST where CONTACT_EMAIL = 'yourmail'");
if (myData != null)
contactEmail = myData.ToString();
}
private void FetchContactID()
{
int contactID = -1;
object myData = connection.FetchMyData("select CONTACT_LIST_ID from QAFranchise.HDR_CONTACT_LIST where CONTACT_EMAIL = 'yourmail'");
if (myData != null)
contactID = Convert.ToInt32(myData);
}
}
And a new class for database operations.
class dbConnection
{
private string _connectionString = "your connection string";
public object FetchMyData(string query)
{
object objVal;
using (SqlConnection con = new SqlConnection(_connectionString))
{
con.Open();
using(SqlCommand cmd = new SqlCommand(query,con))
{
objVal = cmd.ExecuteScalar();
}
}
return objVal;
}
}
Then it will be easier for you to manage.