Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:


C#
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?)
Posted
Comments
Sergey Alexandrovich Kryukov 5-Mar-15 10:20am    
How is that related to intellisense? And do you only write code by intellisense, cannot just write it?
—SA
Member 11410952 5-Mar-15 10:31am    
I mean even if I write code without intelliSense I get the above mentioned error.

using conn;
Sergey Alexandrovich Kryukov 5-Mar-15 11:22am    
What conn? Did you define such namespace? In what assembly? If this is another assembly, did you reference it?
Before doing SQL, connection, anything complicated, learn the basics. Isn't it logical?
—SA
DamithSL 5-Mar-15 10:33am    
where your Connection class located? is it in same project or another class library? have you add reference if you place that file in separate project?
Member 11410952 5-Mar-15 10:35am    
I have added Connection.cs class in App_Code folder in same project.

1 solution

Quote:
Check if your classes build action is set to Compile (right click on your class in solution explorer and click properties).

refer : Intellisense in App_Code in VS2010[^]
 
Share this answer
 
Comments
Member 11410952 5-Mar-15 11:11am    
Wow...It worked...Thank u soooo much (DamithSL)...I was totally lost out bcoz of this error...Finally relieved...U made my day... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900