Reputation: 37
I have the following code working, I just want to display my own column names for each column rather than the ones in the database.
Is there any way I can do that?
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "total_registration";
cmd.Connection = con;
using (SqlDataAdapter a = new SqlDataAdapter(cmd.CommandText, con))
{
DataTable t = new DataTable();
a.Fill(t);
grid.DataSource = t;
}
Upvotes: 2
Views: 3184
Reputation: 35733
after binding datasource set column header text explicitly using the DataGridView.Columns[].HeaderText property:
grid.DataSource = t;
grid.Columns["ID"].HeaderText = "Identifier";
Upvotes: 3
Reputation: 11
Yes, there ist a special SQL-Statement for this.
For example you have a table in your DB with the following columns ID, Name, Age and you want to name them like the following Identification LastName AgeYear
you could use the following sql-statement:
SELECT ID as Identification, Name as LastName, Age as AgeYear FROM db;
Hope it help.
Upvotes: 1