Reputation: 69
I have a gridview like this. I want to show only group_id and groups row. How can I achieve that?
Here is my code:
conn.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM groups WHERE user_id = '" + current_user + "'", conn);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
GroupGrid.DataSource = ds;
GroupGrid.DataBind();
Upvotes: 0
Views: 308
Reputation: 1441
You can handle it with C# Code even you selected all columns from your table
GroupGrid.DataSource = Nothing
GroupGrid.AutoGenerateColumns = False
GroupGrid.Columns(0).Name = "group_id"
GroupGrid.Columns(0).HeaderText = "Group ID"
GroupGrid.Columns(0).DataPropertyName = "group_id"
GroupGrid.Columns(1).Name = "groups"
GroupGrid.Columns(1).HeaderText = "Group"
GroupGrid.Columns(1).DataPropertyName = "groups"
GroupGrid.DataSource = ds;
GroupGrid.DataBind();
Upvotes: 1
Reputation: 14044
So when you use SELECT * FROM groups
it would select/fetch all the column of the table. and thus you can only select/fetch the columns which you are desired to show.
Instead of SELECT * FROM groups
you should be using SELECT group_id, groups FROM groups
will solve the problem
Upvotes: 2