简体   繁体   English

C#访问SQL Server数据库存储过程和视图

[英]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.

相关问题 使用C#将存储过程从解决方案文件夹添加到SQL Server数据库 - Using C# to add stored procedures from solution folder to SQL Server database ASP C#|使用SQL和存储过程更新数据库 - ASP C# | Update Database using SQL and Stored Procedures C#MVC使用SQL Server存储过程构建项目 - C# MVC Structuring a project with SQL Server stored procedures C#Winforms-如何将参数传递给SQL Server存储过程 - C# Winforms - How to Pass Parameters to SQL Server Stored Procedures C# 和 SQL 服务器:更新存储过程有问题 - C# and SQL Server: updating trouble with stored procedures C#中的TransactionScope是否可以触发SQL Server中存储过程中的回滚? - Can TransactionScope in C# trigger rollbacks in stored procedures in SQL server? 使用相同的参数在C#中执行多个SQL Server存储过程 - Executing multiple SQL Server stored procedures in C# with the same parameters 用C#编写Server存储过程 - Writing Server stored procedures in c# 是否可以在C#/ SQL Server中使用表变量作为存储过程的参数? - Is it possible to use in C#/SQL Server a table variable as a parameter for stored procedures? C#和SQL Server存储过程-无法获取输出参数值,返回值有效 - C# & SQL Server stored procedures - can't get output parameter value, return value works
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM