forum

Home / DeveloperSection / Forums / How to close the datareader

How to close the datareader

Manoj Bhatt171304-Oct-2014
this is a simple function that takes care of all the queries:
DataTable ReadIt(string query, params MySqlParameter[] sqlParams)
{
    DataTable dt = new DataTable();
 
    using(MySqlConnection myConnection = new MySqlConnection(sConnection))
    {
        myConnection.Open();
        MySqlCommand myCommand =myConnection.CreateCommand();
        myCommand.CommandText = query;
        foreach (var p in sqlParams)
        {
            myCommand.Parameters.Add(p);
        }
        MySqlDataReader myReader =myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        dt.Load(myReader);
        myReader.Close();
    }
 
    return dt;
}

I want to myReader.Close(); afeter loading data to datatable


Updated on 04-Oct-2014

Can you answer this question?


Answer

1 Answers

Liked By