0

Suppose I have used the following MySQL query:

select * from userinfo;

In the database the following columns are available: username, email, pass, secqu, secan;
Now I want to show only the username, and email columns value into my DataGridView.
Now My Question is: How can I do it? Code like something datagridview.rows[index]. .... something like this is used, but I cannot remember. Can anyone help to do this?

N.B: Please do not reply with the following one:
1. change the query into [select username, email from userinfo;];
2. Change which columns will you want hide or not. As the other columns value are required so I need to use the query.

Chris
  • 8,527
  • 10
  • 34
  • 51
Sondhi
  • 51
  • 1
  • 4
  • 9
  • 1
    possible duplicate of [How to select visible columns in Datagridview bound to DataTable](http://stackoverflow.com/questions/16688760/how-to-select-visible-columns-in-datagridview-bound-to-datatable) – Chris Aug 01 '14 at 16:07
  • The answer is in your question than what you want? and what problem you are getting? – Shell Aug 02 '14 at 03:40

1 Answers1

0

if you don't want to specify the columns in your query and want to fill datagridview with Select * query then you have another option that you can hide columns from the DataGridView.

string[] strShowColumns = new String[] {"username", "email"};
for (int i=0; i < dgv.Columns.Count; i++)
{
    if (!strShowColumns.Contains(dgv.Columns[1].Name))
        dgv.Columns[i].Visible = false;
}
Shell
  • 6,818
  • 11
  • 39
  • 70