工厂提供器DbProviderFactory 实现多种数据库类型类型的DBhelper
程序代码:
class DBHelper { private DbConnection con; private DbCommand com; private DbProviderFactory provider; public DBHelper(int appItemsIndex) { string providerName = ConfigurationManager.ConnectionStrings[appItemsIndex].ProviderName; provider=DbProviderFactories.GetFactory(providerName); con = provider.CreateConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings[appItemsIndex].ConnectionString; com = provider.CreateCommand(); com.Connection = con; //DbParameter a=provider .created } public int ExecuteNonQury(string sqlStr,params DbParameter[] parameter) { con.Open(); = CommandType.Text; = sqlStr; if (parameter != null || parameter.Length > 0) { com.Parameters.AddRange(parameter); } int rel = com.ExecuteNonQuery(); return rel; con.Close(); } public DataTable Table() { string sqlStr = "select * from T_person"; = CommandType.Text; = sqlStr; DbDataAdapter ad = provider.CreateDataAdapter(); ad.SelectCommand = com; DataTable tb = new DataTable(); ad.Fill(tb); return tb; } } class DAL { public int ExecuteNonQury() { string sqlStr = "delete from T_person where id='@ID'"; return new DBHelper ().ExecuteNonQury (sqlStr , ???? } }问号那,该怎么写,希望大家能帮帮忙,或者给我一些例子也行,(这块不太熟),是不是在ExecuteNonQury方法的参数(params DbParameter[] parameter)设置有问题
[ 本帖最后由 lxb932979339 于 2013-5-1 12:28 编辑 ]