Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How do you define Person in Default.aspx.cs with a "using ???.Person"

class1.cs
C#
namespace ClassList
{
    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Phone { get; set; }
        public string Address { get; set; }
    }
}

Default.aspx.cs
C#
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using ???.Person
string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
string selectSql = "SELECT * FROM Members";

List<Person> source = new List<Person>();
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
    SqlCommand myCommand = new SqlCommand(selectSql, myConnection);
    myCommand.CommandType = System.Data.CommandType.Text;

    myConnection.Open();
    SqlDataReader nwReader = myCommand.ExecuteReader();
    while (nwReader.Read())
    {
        source.Add(new Person {
            FirstName = nwReader["firstName"].ToString(),
            LastName = nwReader["lastName"].ToString(),
            Phone = nwReader["Phone"].ToString(),
            Address = nwReader["Address"].ToString});
    }
}
ListView1.DataSource = source;
ListView1.DataBind();
Posted
Updated 5-Nov-14 13:01pm
v3
Comments
Sergey Alexandrovich Kryukov 5-Nov-14 17:05pm    
The question makes no sense: the "using" clause never defines anything. It only provides shortcut naming for assembly-level types. One can always remove all "using" (except "using" statements, don't mix them up) and use fully-qualified names; it won't change anything...
—SA
[no name] 6-Nov-14 2:41am    
You can learn about using namespaces. ;)

1 solution

You can use the following code to use the classes you defined
using ClassList.Person
 
Share this answer
 

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