[英]C# access to SQL Server database stored procedures and views
In my C# application I need access to a SQL Server database. 在我的C#应用程序中,我需要访问SQL Server数据库。 But only to some views and some stored procedures.
但是只限于某些视图和某些存储过程。 Is it advisable to use Entity Framework?
建议使用实体框架吗? Or are there some lightweight methods to get access?
还是有一些轻量级的方法来访问?
Is it advisable to use entityframework?
建议使用实体框架吗?
Yes it is. 是的。
Or ore there some lightweight methods to get access?
还是矿石有一些轻巧的方法可以进入?
That is what Entity Framework is i believe. 我相信这就是实体框架。
Entity Framework + LINQ to SQL = Magic. 实体框架+ LINQ to SQL = Magic。
ADO.NET is much faster than EF and there is no difficulty ADO.NET比EF快得多,没有困难
using (SqlConnection conn = new SqlConnection("Data Source=.; Initial Catalog=DBNAME; Integrated Security=true;"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT ID, NAME FROM VIEWNAME where id > 4550;", conn))
{
// cmd.CommandType = CommandType.StoredProcedure // for SP
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
dictionary.Add(dr.GetInt32(0), dr.GetString(1));
}
}
}
}
Connection string better store in app.config 连接字符串更好地存储在app.config中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.