C# C语言中的类列表

C# C语言中的类列表,c#,class,C#,Class,我的代码C有问题 在数据库用户表中,我有两个电价计划的用户 我需要用从数据库提取到单个用户的平面值填充标签平面 我想创建一个类列表,其中存储了plane的值 我尝试过使用这个解决方案,但没有成功,因为对于multitariff用户,输出只是plane的第一个值,而不是plane的所有值 我将非常感谢你在解决这个问题上给我的任何帮助 这是我的密码: string plane; List<string> planeList = new List<string>(); pu

我的代码C有问题

在数据库用户表中,我有两个电价计划的用户

我需要用从数据库提取到单个用户的平面值填充标签平面

我想创建一个类列表,其中存储了plane的值

我尝试过使用这个解决方案,但没有成功,因为对于multitariff用户,输出只是plane的第一个值,而不是plane的所有值

我将非常感谢你在解决这个问题上给我的任何帮助

这是我的密码:

string plane;

List<string> planeList = new List<string>();

public class Lists
{
    static void Main()
    {
        List<string> planeList = new List<string>();
    }
}

protected void Users()
{
    using (OdbcConnection cn =
        new OdbcConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
    {
        sql = " SELECT * FROM Users WHERE Id = ? ";

        using (OdbcCommand command =
            new OdbcCommand(sql, cn))
        {
            try
            {
                command.Parameters.AddWithValue("param1", Server.UrlDecode(Request.Cookies["Id"].Value));
                command.Connection.Open();

                using (OdbcDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        plane = reader["plane"].ToString();
                        planeList.Add(plane.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("operation failed!", ex);
            }
            finally
            {
                command.Connection.Close();
            }
        }
    }
}


protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Users();

        if (Request.Cookies["Id"] != null)
        {
            foreach (string plane in planeList)
            {
                plane.Text = "User plane: " + plane.ToString().Trim() + "<br />";
            }
        }
    }
}

每次都会覆盖标签的值:

foreach (string plane in planeList)
{
    plane.Text = "User plane: " + plane.ToString().Trim() + "<br />";
}
您应该连接字符串,而不是覆盖它:

plane.Text = "User plane: ";
foreach (string item in planeList)
{
    plane.Text += item.ToString().Trim() + "<br />"; // I suppose plane is a label here, so your foreach variable should be called different (item in this case)
}

你所说的plane.Text是什么意思???@Hamamelis你能用一些示例数据显示你的表的模式吗?你正在从一个记录平面上用一个特定的Id从用户那里读取一列,但不知何故你希望从该列中读取多个值。。。你能告诉我们你的用户表的结构吗?