指点

.Net技术 码拜 8年前 (2016-02-26) 1028次浏览
using System;
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”比方法“DataAccess.DBImpl.DBImpl(DataAccess.DBType.DataBaseType, string)”的可访问性低
把参数类型“DataAccess.DBType.DataBaseType”访问修饰符调高,例如设置为public。

10

意思是DataBaseType可访问性是internal,但是却做了一个public方法的参数。
别人调用这个方法的时候,怎么传入DataBaseType这个参数呢?原因是它是私有类型。所以这个public方法是无法调用的。
所以编译器就报错了。

20

找到DataAccess.DBType.DataBaseType定义的地方,把它的访问修饰符改为public,然后编译运行试试。
怎么找DataAccess.DBType.DataBaseType,可以在vs中按ctrl+f,查找。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明指点
喜欢 (0)
[1034331897@qq.com]
分享 (0)