前天到一家公司面试,面试官问了我这样一个asp.net题目,该怎样作答呢? 如果让你写一个类,能同时对SQL Server 2000和Oracle数据库进行操作(与具体数据库无关的跨数据库操作的类),怎样写?能详细说明一下吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1 使用orm2 写一个基类idbo,ado.net控件全部使用相应的接口来写,SQL Server 2000和Oracle分别继承这个基类idbo 对不起,我没有说清楚:他让我写一个能对数据库(SQL Server 2000和Oracle)具体操作的类——可以对表中的记录进行查询、添加、修改、删除。让我具体写,我不知道该怎样写。请帮我一下吧! ADO.NET现有一个, Sql Server 与 OLEDB{Access} 共用的, 你试着看看吧.public enum ProviderType : int {SqlClient = 0, OLEDB = 1} public class ProviderFactory { public ProviderFactory(ProviderType provider) { _pType = provider; _initClass(); } public ProviderFactory() { _initClass(); } private ProviderType _pType = ProviderType.SqlClient; private bool _pTypeSet = false; private Type[] _conType, _comType, _parmType, _daType; private void _initClass() { _conType = new Type[2]; _comType = new Type[2]; _parmType = new Type[2]; _daType = new Type[2]; // Initialize the types for the providers _conType[(int)ProviderType.SqlClient] = typeof(SqlConnection); _conType[(int)ProviderType.OLEDB] = typeof(OleDbConnection); _comType[(int)ProviderType.SqlClient] = typeof(SqlCommand); _comType[(int)ProviderType.OLEDB] = typeof(OleDbCommand); _parmType[(int)ProviderType.SqlClient] = typeof(SqlParameter); _parmType[(int)ProviderType.OLEDB] = typeof(OleDbParameter); _daType[(int)ProviderType.SqlClient] = typeof(SqlDataAdapter); _daType[(int)ProviderType.OLEDB] = typeof(OleDbDataAdapter); } public ProviderType Provider { get { return _pType; } set { if (_pTypeSet) { throw new ReadOnlyException("Provider already set to " + _pType.ToString()); } else { _pType = value; _pTypeSet = true; } } } public IDbDataAdapter CreateDataAdapterb(string commandText, IDbConnection connection) { IDataAdapter d; IDbDataAdapter da; d = (IDataAdapter)Activator.CreateInstance(_daType[(int)_pType], false); da = (IDbDataAdapter)d; da.SelectCommand = this.CreateCommand(commandText, connection); return da; } public IDbDataAdapter CreateDataAdapterb(IDbCommand commandText) { IDataAdapter d; IDbDataAdapter da; d = (IDataAdapter)Activator.CreateInstance(_daType[(int)_pType], false); da = (IDbDataAdapter)d; da.SelectCommand = commandText; return da; } public IDataAdapter CreateDataAdapter(string commandText, IDbConnection connection) { IDataAdapter d; IDbDataAdapter da; d = (IDataAdapter)Activator.CreateInstance(_daType[(int)_pType], false); da = (IDbDataAdapter)d; da.SelectCommand = this.CreateCommand(commandText, connection); return d; } public IDataAdapter CreateDataAdapter(IDbCommand commandText) { IDataAdapter d; IDbDataAdapter da; d = (IDataAdapter)Activator.CreateInstance(_daType[(int)_pType], false); da = (IDbDataAdapter)d; da.SelectCommand = commandText; return d; } public IDataParameter CreateParameter(string paramName, DbType paramType) { IDataParameter p; p = (IDataParameter)Activator.CreateInstance(_parmType[(int)_pType], false); p.ParameterName = paramName; p.DbType = paramType; return p; } public IDataParameter CreateParameter(string paramName, DbType paramType, Object value) { IDataParameter p; p = (IDataParameter)Activator.CreateInstance(_parmType[(int)_pType], false); p.ParameterName = paramName; p.DbType = paramType; p.Value = value; return p; } public IDbConnection CreateConnection(string connect) { IDbConnection c; c = (IDbConnection)Activator.CreateInstance(_conType[(int)_pType], false); c.ConnectionString = connect; return c; } public IDbCommand CreateCommand(string cmdText) { IDbCommand c; c = (IDbCommand)Activator.CreateInstance(_comType[(int)_pType], false); c.CommandText = cmdText; return c; } public IDbCommand CreateCommand(string cmdText, IDbConnection connection) { IDbCommand c; c = (IDbCommand)Activator.CreateInstance(_comType[(int)_pType], false); c.CommandText = cmdText; c.Connection = connection; return c; } public DataSet mkFillDataSet(IDbCommand commandText, string DataTableName, int FillStartRecord, int FillMaxRecord) { DataSet dsTemp = new DataSet(); if (this.Provider == ProviderType.SqlClient) { SqlDataAdapter sqlDA = new SqlDataAdapter(commandText.CommandText, (SqlConnection)commandText.Connection); sqlDA.Fill(dsTemp, FillStartRecord, FillMaxRecord, DataTableName); } else if (this.Provider == ProviderType.OLEDB) { OleDbDataAdapter oleDA = new OleDbDataAdapter(commandText.CommandText, (OleDbConnection)commandText.Connection); oleDA.Fill(dsTemp, FillStartRecord, FillMaxRecord, DataTableName); } else { DataTable dtNull = new DataTable(DataTableName); dsTemp.Tables.Add(dtNull); } return dsTemp; } } 求解一C#正则问题 如何给DropDownList每一项赋值 asp.net模板的奇怪问题 !!!!紧急问题! ~IE无法打开? 这个还真要点经验才能解决哦 关于事件的使用 关于验证码的一点奇怪的问题 急急急! 提示框问题!!! 开发asp.net进销存,如何安装部署啊, 为什么.net的mail组件发不了带附件的mail,我用的是默认本地域的smtp service.急!! 高分求解Web服务器报告以下错误 怎么也删除不了,怪了
2 写一个基类idbo,ado.net控件全部使用相应的接口来写,SQL Server 2000和Oracle分别继承这个基类idbo
{ public ProviderFactory(ProviderType provider)
{
_pType = provider;
_initClass();
} public ProviderFactory()
{
_initClass();
} private ProviderType _pType = ProviderType.SqlClient;
private bool _pTypeSet = false;
private Type[] _conType, _comType, _parmType, _daType; private void _initClass()
{
_conType = new Type[2];
_comType = new Type[2];
_parmType = new Type[2];
_daType = new Type[2]; // Initialize the types for the providers
_conType[(int)ProviderType.SqlClient] = typeof(SqlConnection);
_conType[(int)ProviderType.OLEDB] = typeof(OleDbConnection);
_comType[(int)ProviderType.SqlClient] = typeof(SqlCommand);
_comType[(int)ProviderType.OLEDB] = typeof(OleDbCommand);
_parmType[(int)ProviderType.SqlClient] = typeof(SqlParameter);
_parmType[(int)ProviderType.OLEDB] = typeof(OleDbParameter);
_daType[(int)ProviderType.SqlClient] = typeof(SqlDataAdapter);
_daType[(int)ProviderType.OLEDB] = typeof(OleDbDataAdapter);
} public ProviderType Provider
{
get
{
return _pType;
}
set
{
if (_pTypeSet)
{
throw new ReadOnlyException("Provider already set to " + _pType.ToString());
}
else
{
_pType = value;
_pTypeSet = true;
}
}
} public IDbDataAdapter CreateDataAdapterb(string commandText, IDbConnection connection)
{
IDataAdapter d;
IDbDataAdapter da; d = (IDataAdapter)Activator.CreateInstance(_daType[(int)_pType], false);
da = (IDbDataAdapter)d;
da.SelectCommand = this.CreateCommand(commandText, connection);
return da;
} public IDbDataAdapter CreateDataAdapterb(IDbCommand commandText)
{
IDataAdapter d;
IDbDataAdapter da; d = (IDataAdapter)Activator.CreateInstance(_daType[(int)_pType], false);
da = (IDbDataAdapter)d;
da.SelectCommand = commandText;
return da;
} public IDataAdapter CreateDataAdapter(string commandText, IDbConnection connection)
{
IDataAdapter d;
IDbDataAdapter da; d = (IDataAdapter)Activator.CreateInstance(_daType[(int)_pType], false);
da = (IDbDataAdapter)d;
da.SelectCommand = this.CreateCommand(commandText, connection);
return d;
} public IDataAdapter CreateDataAdapter(IDbCommand commandText)
{
IDataAdapter d;
IDbDataAdapter da; d = (IDataAdapter)Activator.CreateInstance(_daType[(int)_pType], false);
da = (IDbDataAdapter)d;
da.SelectCommand = commandText;
return d;
} public IDataParameter CreateParameter(string paramName, DbType paramType)
{
IDataParameter p;
p = (IDataParameter)Activator.CreateInstance(_parmType[(int)_pType], false);
p.ParameterName = paramName;
p.DbType = paramType;
return p;
} public IDataParameter CreateParameter(string paramName, DbType paramType, Object value)
{
IDataParameter p;
p = (IDataParameter)Activator.CreateInstance(_parmType[(int)_pType], false);
p.ParameterName = paramName;
p.DbType = paramType;
p.Value = value;
return p;
} public IDbConnection CreateConnection(string connect)
{
IDbConnection c;
c = (IDbConnection)Activator.CreateInstance(_conType[(int)_pType], false);
c.ConnectionString = connect;
return c;
} public IDbCommand CreateCommand(string cmdText)
{
IDbCommand c;
c = (IDbCommand)Activator.CreateInstance(_comType[(int)_pType], false);
c.CommandText = cmdText;
return c;
} public IDbCommand CreateCommand(string cmdText, IDbConnection connection)
{
IDbCommand c;
c = (IDbCommand)Activator.CreateInstance(_comType[(int)_pType], false);
c.CommandText = cmdText;
c.Connection = connection;
return c;
} public DataSet mkFillDataSet(IDbCommand commandText, string DataTableName, int FillStartRecord, int FillMaxRecord)
{
DataSet dsTemp = new DataSet();
if (this.Provider == ProviderType.SqlClient)
{
SqlDataAdapter sqlDA = new SqlDataAdapter(commandText.CommandText, (SqlConnection)commandText.Connection);
sqlDA.Fill(dsTemp, FillStartRecord, FillMaxRecord, DataTableName);
}
else if (this.Provider == ProviderType.OLEDB)
{
OleDbDataAdapter oleDA = new OleDbDataAdapter(commandText.CommandText, (OleDbConnection)commandText.Connection);
oleDA.Fill(dsTemp, FillStartRecord, FillMaxRecord, DataTableName);
}
else
{
DataTable dtNull = new DataTable(DataTableName);
dsTemp.Tables.Add(dtNull);
}
return dsTemp;
}
}