0

我的dataGridViewwinForm (C#) 应用程序中有一个显示玩家列表的应用程序。

我已经成功地将它与数据库绑定,并正确显示了所有列,即 PlayerName、Age、Runs 等。

现在我想dataGridViewrun time不添加到数据库的情况下再添加一列,即“CurrentScore”。

请告诉如何执行此品尝。是否可以以编程方式添加新列?

    private  void playerList(int teamID)
    {


            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            string query = "SELECT PlayerName AS [Player Name] ,Age , Runs FROM Players WHERE Team_id= " + teamID;

            SqlCommand cmd = new SqlCommand(query, con);
            adapter = new SqlDataAdapter(cmd);
            adapter.Fill(ds, "Players");
            dGridPlayers.DataSource = ds.Tables["Players"];

        }

此代码运行良好,但无法添加新的临时列“CurrentScore”

4

1 回答 1

0

您可以编辑您的查询并添加一个虚拟列:

string query = "SELECT player_name AS [Player Name] ,
skill As [Skill], '' AS [CurrentScore]
FROM Players WHERE Team_id= " + teamID;
于 2013-07-25T00:59:09.023 回答