R
Randall Parker
I'm just learning ADO.Net having previously used DAO, ADO, JDBC, ODBC, and other
database drivers.
One thing odd strikes me from the source code examples of driver usage that I'm
looking at: A lot of class names that are specific to each driver get used in the
examples.
For example for MySQL using either MySQL's own driver or the CoreLabs driver one does
something like this:
using System;
using System.Data;
using System.Diagnostics;
using MySql.Data.MySqlClient;
// I'm leaving out some class declaration stuff here...
string DataSource = "localhost";
string Database = "test";
string UserID = "root";
string Password = "root";
string MyConnString = Data Source=" + DataSource +
";Database=" + Database +
";User ID=" + UserID +
";Password=" + Password;
MySqlConnection dbConn = new MySqlConnection(MyConString);
dbConn.Open();
MySqlCommand dbCmd = new MySqlCommand();
MySqlDataAdapter dbAdapter = new MySqlDataAdapter();
Note that not only is one driver-specific for creating the connection but also for
creating the SQL Command object and the adapter object.
To me it would make more sense to have syntax where one did something like:
MySqlConnection dbConn = new MySqlConnection(MyConString);
dbConn.Open();
BaseCommand dbCmd = dbConn.GetCommand();
BaseAdapter dbAdapter = dbConn.GetAdapter();
In this fictitious example I use "BaseCommand" and "BaseAdapter" as base classes and
the connection object dbConn knows how to get driver-specific derived classes in a
way that avoids mentioning those class names in the source code.
So is there some way to do that sort of thing? Or does one have to mention
driver-specific class names a lot more?
database drivers.
One thing odd strikes me from the source code examples of driver usage that I'm
looking at: A lot of class names that are specific to each driver get used in the
examples.
For example for MySQL using either MySQL's own driver or the CoreLabs driver one does
something like this:
using System;
using System.Data;
using System.Diagnostics;
using MySql.Data.MySqlClient;
// I'm leaving out some class declaration stuff here...
string DataSource = "localhost";
string Database = "test";
string UserID = "root";
string Password = "root";
string MyConnString = Data Source=" + DataSource +
";Database=" + Database +
";User ID=" + UserID +
";Password=" + Password;
MySqlConnection dbConn = new MySqlConnection(MyConString);
dbConn.Open();
MySqlCommand dbCmd = new MySqlCommand();
MySqlDataAdapter dbAdapter = new MySqlDataAdapter();
Note that not only is one driver-specific for creating the connection but also for
creating the SQL Command object and the adapter object.
To me it would make more sense to have syntax where one did something like:
MySqlConnection dbConn = new MySqlConnection(MyConString);
dbConn.Open();
BaseCommand dbCmd = dbConn.GetCommand();
BaseAdapter dbAdapter = dbConn.GetAdapter();
In this fictitious example I use "BaseCommand" and "BaseAdapter" as base classes and
the connection object dbConn knows how to get driver-specific derived classes in a
way that avoids mentioning those class names in the source code.
So is there some way to do that sort of thing? Or does one have to mention
driver-specific class names a lot more?