There is no way to instantiate ADO.Net objects in a provider independent
way. This is in contrast to Java where you have the DriverManager to
help. But there is something you can do. In one of my projects, I
created a Database class and inside that class I instantiate the
connection and command objects for the db type that I want. Then I
implement methods like the following on that class
DbDataAdapter GetAdapter(string selectsql) {...}
IDbRecord GetRecord() {..}
These functions call the appropriate parts of my driver specific
connection and command objects and return interfaces. This allows me to
write db-independent code in my project. Below is one snippet of code
that uses the database class
String sql = "blah blah"
Database db = new Database();
IDataReader reader = db.GetReader(sql);
IDataRecord record = db.GetRecord();
while (reader.Read())
{
int field1 = (int)record["id"];
.. access other fields same way...
}
Note that this doesn't address the ADO.Net's lack of a common SQL
Exception class.
Hope this helps,
Reggie
> -----Original Message-----
> From: dotnet discussion [mailto:[EMAIL PROTECTED]] On Behalf
Of
> Marian Aioanei
> Sent: Tuesday, May 21, 2002 12:30 PM
> To: [EMAIL PROTECTED]
> Subject: [DOTNET] ADO .NET provider-independent code
>
> Hi,
>
> Why there is no way to obtain a reference to a DataAdapter in a
provider-
> independent manner in ADO.NET ? While IDbConnection has the
CreateCommand
> method to get a Command object, why there is no CreateDataAdapter
method
> in IDbConnection ?
>
>
> TIA,
> Marian Aioanei
>
> You can read messages from the DOTNET archive, unsubscribe from
DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.