c# IDataReader SqlDataReader difference
问题 Can someone tell me the difference between these two pieces of code? Why use IDataReader? using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { // get data from the reader } } using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { // get data from the reader } } 回答1: SqlDataReader implements the interface IDataReader . So do all other ADO.NET drivers (Oracle, MySql, etc). You can use IDataReader , so that if you plan to change database engine some