How to read specific column and cell in mysql in c#?

Prasetyo Jean picture Prasetyo Jean · Apr 9, 2013 · Viewed 10.4k times · Source

I use ExecuteReader to select all (SELECT*) for all field like this

string query = "SELECT* FROM tb_patient_information ";
        if (this.OpenConnection() == true)
        { //Create Command
            MySqlCommand cmd = new MySqlCommand(query, connection);
            //Create a data reader and Execute the command
            MySqlDataReader dataReader = cmd.ExecuteReader();
            while (dataReader.Read())
            { ... }

but I only want to select in specific column and cell like in red square.. like this pictureI only want to select in specific cell&column like in red square

Answer

John Woo picture John Woo · Apr 9, 2013

You can get the specific column inside the while clause.

while (dataReader.Read())
{ 
    var _column = dataReader["Nama_Kategori"];
}