using System; using System.Collections.Generic; using System.Linq; using System.Text; using Entity; using System.Diagnostics; using System.Data.SqlClient; using System.Data; using System.Configuration; namespace DAL { public class SqlDBHelper { priva
在平时开发过程中常常需要取一个方法的返回值,BOSS写了一个返回值类,做个练习以备不时之需: 返回值支持泛型和非泛型 先贴上代码: 非泛型返回值类: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; namespace WindowsFormsApplication31 { [Serializable]
新的返回值语法 让我们讲一下新的返回值语法,这个语法还能看到auto的另一个用处.在以前版本的C和C++中,返回值的类型必须写在函数的前面: int multiply(int x, int y) 在C++11中,你可以把返回类型放在函数声明的后面,用auto代替前面的返回类型,像这样: auto multiply(int x, int y) -> int 但是为什么我要这样用?让我们看一个证明这个语法好处的例子.一个包含枚举的类: class Person { public: enum Pers
在写存储过程时经常会遇到需要拼接SQL语句的情况,一般情况下仅仅是为了执行拼接后的语句使用exec(@sql)即可. 而今天的一个存储过程却需要获取动态SQL的查询结果. 需求描述:在某表中根据Id值查询Cost值(表名不确定但表结构确定,如下面的Product表) 如果不考虑获取返回值,我们这样写即可: ) ) ,) ) set @tableName='Product' ' set @sql='select Cost from '+@tableName+' where Id='+@id exe
一: 执行sql语句,返回受影响的行数 在mysql里面,如果没有影响,那么返回行数为 -1 ,sqlserver 里面 还没有测试过 using (var ctx = new MyDbContext()) { ctx.Database.ExecuteSqlCommand("UPDATE Person SET Name = 'Michael' WHERE PersonID = 1"); } 二 : Database.SqlQuery<T> EF5执行sql查询语句
1.首先展示创建sql server存储过程的语句,创建一个简单的存储过程,测试用. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[register_info] ), ), ), ), ), @create_time datetime AS BEGIN ); BEGIN TRY BEGIN TRANSACTION; --插入注册信息,这里未做任何验证,直接插入 INSERT into regist