我正在创建一个MVC 6项目,我宁愿使用Classic ADO.net而不是实体框架7.但是,它说两个DataTable
和两个都找不到名称空间SqlDataAdapter
.我有一个使用System.Data
和System.Data.SqlClient
声明.在我尝试构建项目之前,它不显示错误.
我想我在某处看到这两个名字空间没有在新版本中实现.如果是这样,有另一种方法可以做到这一点,还是我错过了依赖或使用声明?
码:
public static DataTable GetLog(string appName)
{
DataTable table = new DataTable("ApplicationLog");
SqlDataAdapter da = null;
using (SqlConnection conn = DB.GetSqlConnection())
{
SqlCommand cmd = new SqlCommand("select * from ApplicationLog where application_name = @appname", conn);
cmd.Parameters.Add(new SqlParameter("appname", System.Data.SqlDbType.NVarChar, 100));
cmd.Parameters["appname"].Value = appName;
da = new SqlDataAdapter(cmd);
int res = da.Fill(table);
}
return table;
}
我的project.json
{ "userSecretsId": "aspnet5-ASPDemo-b25bb1cc-00e6-401e-9f49-5b59c08a030f", "version": "1.0.0-*", "compilationOptions": { "emitEntryPoint": true }, "dependencies": { "Bestro": "1.0.0-*", "EntityFramework.Core": "7.0.0-rc1-final", "EntityFramework.Commands": "7.0.0-rc1-final", "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", "Microsoft.ApplicationInsights.AspNet": "1.0.0-rc1", "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final", "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final", "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final", "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc": "6.0.0-rc1-final", "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final", "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final", "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final", "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final", "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final", "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final", "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final", "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final", "Microsoft.Extensions.Logging": "1.0.0-rc1-final", "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final", "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final", "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final", "DataTables.AspNet.AspNet5": "2.0.0-beta2" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel", "ef": "EntityFramework.Commands" }, "frameworks": { "dnx451": { "frameworkAssemblies": { "System.configuration": "4.0.0.0", "System.Data": "4.0.0.0" } } }, "exclude": [ "wwwroot", "node_modules" ], "publishExclude": [ "**.user", "**.vspscc" ], "scripts": { "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ] } }
我最终尝试了很多不同的组件,试图让它得到遵守.如果有使用参考,请告诉我.