在我的asp.net代码中出错

时间:2014-04-27 13:39:48

标签: c# asp.net ms-access-2007

这是我在运行代码并尝试获取记录时遇到的错误

  

不支持关键字:'provider'。

     

描述:执行期间发生了未处理的异常   当前的网络请求。请查看堆栈跟踪了解更多信息   有关错误的信息以及它在代码中的起源。

     

异常详细信息:System.ArgumentException:不支持关键字:   '提供商'。

我的代码工作正常我使用的是Access 2007。然后我需要在表中添加更多列后才能收到此错误

这是我的web.cfg

  <connectionStrings>
<add name="ConnectionStringName" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source='|DataDirectory|\mfaridalam1.accdb'; Persist Security Info=False" />
  </connectionStrings>

这就是我使用Configuration Manager

获取连接字符串的方法
ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString.ToString();

这就是我调用我的功能的方式

 newtable = Class1.GetLastRec(ConnectionString, "LastAlbum");

这是我的功能

  public static string GetLastRec(string Connectionstring, string ColumnName)
    {
        // string conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\AGENTJ.AGENTJ-PC\Documents\Visual Studio 2010\WebSites\mfaridalam\App_Data\mfaridalam1.accdb;    Persist Security Info=False;";
        string newAlbum = "";
        string conStr = Connectionstring;
        string Column = ColumnName;
        OleDbConnection con = new OleDbConnection(conStr);
        try
        {
            con.Open();
            OleDbCommand cmd = new OleDbCommand("Select * from LastInfo", con);
            OleDbDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                string input = dr[Column].ToString();
                newAlbum = input;
                if (newAlbum.Substring(0, 1) == "c")
                {
                    //input.Trim();
                    input = input.Substring(3);
                    int cont = Convert.ToInt32(input) + 1;
                    newAlbum = "c00" + cont.ToString();
                }
                else
                {
                    input = input.Substring(3);
                    int cont = Convert.ToInt32(input) + 1;
                    newAlbum = "v00" + cont.ToString();
                }
            }
            con.Close();
            // Response.Write(newtable);
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
        return newAlbum;

    }

0 个答案:

没有答案