0

Short and probably easy question, I don't want to view in dataGridView columnID and few more columns as there is no use of viewing that info.

I have a clear code, the connection is open, the data loads fine and the comment code (btw most common solution in google) gives empty table with all columns (no rows).

I tried so many things that I can't even list them there :(

Any ideas?

DataTable SqlDataTable = new DataTable();
MySqlDataReader reader;

MySqlCommand sqlCommand = new MySqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandText = "SELECT * FROM table_name";

reader = sqlCommand.ExecuteReader();

//while (reader.Read())
//{
//    string columnID = reader["columnID"].ToString();                        
//}

SqlDataTable.Load(reader);

reader.Close();
sqlConnection.Close();

DataGridView = SqlDataTable;

1 Answer 1

1

First when U want view data in DataGridView U should set the data source of it's like

DataGridView.DataSource = yourDataTable

Second, if U want to hide DataGridView column, U most know the index of the column or the name and then you can use this code I assume the first column is ID So

By Index

DataGridView.Columns[0].Visible = false;

By Name

DataGridView.Columns["ID"].Visible = false;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.