using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
using System.Data;
using System.Data.Common;
using System.Windows.Forms;
namespace DataAccess
{
public class DBImpl
{
private DbConnection dbConn;
private DbCommand dbConmmand;
private DbDataAdapter dbDataAdapter;
private string connString;
private DBType.DataBaseType dbType;
public DBImpl(DBType.DataBaseType dbType, string connString)
{
switch (dbType)
{
case DBType.DataBaseType.Access:
dbConn = new OleDbConnection(connString);
break;
}
this.connString = connString;
this.dbType = dbType;
}
public DataTable ExecuteQuery(string strSql)
{
try
{
switch (dbType)
{
case DBType.DataBaseType.Access:
dbDataAdapter = new OleDbDataAdapter(strSql, dbConn as OleDbConnection);
break;
}
DataSet ds = new DataSet();
dbDataAdapter.Fill(ds);
return ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
public int ExecuteNonQuery(string strSql)
{
int jie = 0;
try
{
dbConn.Open();
switch (dbType)
{
case DBType.DataBaseType.Access:
dbConmmand = new OleDbCommand(strSql, dbConn as OleDbConnection);
break;
}
jie = dbConmmand.ExecuteNonQuery();
dbConn.Close();
}
catch (Exception es)
{
MessageBox.Show(es.Message);
//return false;
}
return jie;
}
}
}
错误 可访问性不一致: 参数类型“DataAccess.DBType.DataBaseType”比方法“DataAccess.DBImpl.DBImpl(DataAccess.DBType.DataBaseType, string)”的可访问性低
10
把参数类型“DataAccess.DBType.DataBaseType”访问修饰符调高,例如设置为public。
10
别人调用这个方法的时候,怎么传入DataBaseType这个参数呢?原因是它是私有类型。所以这个public方法是无法调用的。
所以编译器就报错了。
20
怎么找DataAccess.DBType.DataBaseType,可以在vs中按ctrl+f,查找。