基本db.Query()

时间:2018-03-11 02:15:44

标签: c# asp.net asp.net-mvc

我知道此问题已经涵盖过,但经过几个小时阅读其他帖子,文档和试用后,我感到很茫然。我是.Net和C#的新手,所以如果这对其他人来说是微不足道,我会道歉。

我收到以下错误:

  

处理请求时发生未处理的异常。

     

TypeLoadException:无法加载类型' System.Data.Common.DbProviderFactories' >来自汇编' System.Data,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'。

     

WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(string> connectionString)

在下面第9行:@foreach ...

@using WebMatrix.Data;
@{
    var dbconn = Database.OpenConnectionString(@"Provider = .NET Framework 
    Data Provider for OLE DB; Data Source = C:\Users\...dbName.accdb");
    string selStr = "SELECT * From EquipList";
    }

    <table><tr>
    @foreach (dynamic row in dbconn.Query(selStr))
    {<tr>
        <td>@row.recordID
    </tr>}</table>

堆栈跟踪:

System.TypeLoadException: Could not load type             
    'System.Data.Common.DbProviderFactories' from assembly 'System.Data, 
    Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(String 
    connectionString)
at WebMatrix.Data.Database.get_Connection()
at WebMatrix.Data.Database.EnsureConnectionOpen()
at WebMatrix.Data.Database.<QueryInternal>d__0.MoveNext()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at WebMatrix.Data.Database.Query(String commandText, Object[] parameters)
at logCalc.Pages.Test_Page.<ExecuteAsync>d__0.MoveNext() in 
    C:\Users\...\Pages\Test.cshtml:line 18
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebugger
    Notification(Task task)
at Microsoft.AspNetCore.Mvc.Razor.RazorView<RenderPageCoreAsync>d__16.
    MoveNext()
--- End of stack trace from previous location where exception was thrown ---

我已确认包含并识别WebMatrix.Data.dll。基于堆栈跟踪,似乎正在建立连接,并且我不能简化查询。有什么建议吗?

0 个答案:

没有答案