Hello I have created below namespace in Connection.cs class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace conn
{
public class Connection
{
public SqlConnection con;
public SqlCommand cmd;
//public SqlDataAdapter adt;
string StrError;
public Connection()
{
try
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["PortfolioMgt"].ConnectionString);
}
catch (SqlException sqlEx)
{
StrError = sqlEx.Message;
}
catch (Exception ex)
{
StrError = ex.Message;
}
}
public void Open_Connection()
{
try
{
con.Open();
}
catch (SqlException sqlEx)
{
StrError = sqlEx.Message;
}
catch (Exception ex)
{
StrError = ex.Message;
}
}
public void Close_Connection()
{
try
{
con.Close();
}
catch (SqlException sqlEx)
{
StrError = sqlEx.Message;
}
catch (Exception ex)
{
StrError = ex.Message;
}
}
}
}
I wanted to use a customized namespace(conn) on Login.aspx.cs page. The code for Login page is as below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using conn;
public partial class Login : System.Web.UI.Page
{
Connection con = new Connection();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
int investorId;
investorId=con.select_Inv_Login(txtUserName.Text, txtPassword.Text);
if(investorId!=0)
{
Session["inv_id"] = investorId;
Response.Redirect("~/MyProfile.aspx");
}
else
{
lblMsg.Visible = true;
lblMsg.Text = "User Name or Password incorrect";
}
}
}
Once I try to write 'using conn;' it gave me below error:
The type or namespace name 'conn' could not be found (are you missing a using directive or an assembly reference?)