Microsoft Jet 数据库引擎找不到输入表或查询 'Admin'。 确定它是否存在,以及它的名称的拼写是否正确。
DAL层代码如下:
/// <summary>
/// 检查用户名是否重复
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool CheckEqualName(string name)
{
string sql = "select count(1) from Admin where LoginName=?";
int res;
OleDbParameter[] parameters = new OleDbParameter[1];
parameters[0] = new OleDbParameter("@LoginName", OleDbType.VarChar);
parameters[0].Value = name;
res = AccessorDB.ExecuteScalar(sql, parameters);
if (res > 0)
{
return true;
}
else
{
return false;
}
}
帮助类代码如下:
private static String connectionString = ConfigurationManager.AppSettings["OLEDBCONNECTIONSTRING"] + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["dbPath"]);
public AccessorDB() { }
//执行单条语句返回第一行第一列,可以用来返回count(*)
public static int ExecuteScalar(string sql, OleDbParameter[] parameters)
{
//Debug.WriteLine(sql);
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand cmd = new OleDbCommand(sql, connection);
try
{
connection.Open();
if (parameters != null) cmd.Parameters.AddRange(parameters);
int value = Int32.Parse(cmd.ExecuteScalar().ToString());
return value;
}
catch (Exception e)
{
throw e;
}
}
}
配置文件如下:
<appSettings>
<!-- access 连接字符串-->
<add key="OLEDBCONNECTIONSTRING" value="provider=microsoft.jet.oledb.4.0;data source="/>
<add key="dbPath" value="~/App_Data/xys.mdb"/>
<add key="CookieDomain" value=""/>
------解决方案--------------------
晕没有admin 表