Re: confusion on interface IDataReader
Peter Osucha <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Ahhh, duh! Thanks for clearing that up Joe. I was seeing the same thing for IDbCommand and it puzzled me. Now it makes sense. Peter > -----Original Message----- > From: Discussion relating to the specifics of the C# and > Managed C++ languages [mailto:[email protected]] > On Behalf Of Joe Mayo > Sent: Tuesday, June 06, 2006 4:42 PM > To: [email protected] > Subject: Re: [DOTNET-CX] confusion on interface IDataReader > > Hi Peter, > > SqlCommand.ExecuteReader will return a SqlDataReader. Since > SqlDataReader implements the IDataReader interface, it can be > assigned to a variable of the IDataReader interface type, but > it is still a SqlDataReader. > > Joe > http://www.csharp-station.com > > > -----Original Message----- > > From: Discussion relating to the specifics of the C# and > Managed C++ > > languages [mailto:[email protected]] On Behalf Of Peter > > Osucha > > Sent: Tuesday, June 06, 2006 2:33 PM > > To: [email protected] > > Subject: [DOTNET-CX] confusion on interface IDataReader > > > > I was looking over some example code that was handling data > access to > > a SQL db. A method for the code was similar to.... > > > > public IDataReader PerformStoredProcedure_DataReader ( > string spName, > > CommandBehavior behavior ) { > > IDataReader result = null; > > SqlCommand cmd = new SqlCommand ( spName, > (SqlConnection)Connection ); > > cmd.CommandType = CommandType.StoredProcedure; > > result = cmd.ExecuteReader ( behavior ); > > return result; > > } > > > > Now what has me confused is that this method returns an > object of type > > IDataReader - which I thought (from reviewing MSDN) was not allowed > > since IDataReader is an interface (ie, I thought such a > method could > > return an object that implemented IDataReader but not an > instance of > > an IDataReader object itself since there really wasn't any > such thing > > as an IDataReader object). IOW, it seems that there should be no > > problem returning an object of, say, type SqlDataReader from this > > method. > > > > I'm obviously not understanding something. Why is it allowed to > > return on object of type IDataReader here? > > > > Peter =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com