Domanda

I have a dataGridView in my winForm (C#) application to display a list of Players.

I have successfully bound it with the database and its showing all columns i.e PlayerName, Age, Runs etc. correctly.

Now i want to add one more columns i.e 'CurrentScore' to this dataGridView at run time without adding to database.

Plz tell how to perform this tast. Is it possible to add new column programmatically ??

    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"];

        }

this code is working perfectly but not able to add new temporary column 'CurrentScore`

È stato utile?

Soluzione

You can just edit your query and add a dummy column:

string query = "SELECT player_name AS [Player Name] ,
skill As [Skill], '' AS [CurrentScore]
FROM Players WHERE Team_id= " + teamID;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top