コード例 #1
0
        public static int InsertModel(DeviceModelEntity entity)
        {
            using (var conn = new SqlConnection(ConnStr))
            {
                conn.Open();

                var sql = @"
 INSERT INTO Configuration.dbo.tbl_DeviceModel
         ( TypeID ,
           DeviceModel ,
           CreateDateTime ,
           UpdateDateTime ,
           CreateUser,
           UpdateUser
         )
 VALUES  ( @TypeID , -- TypeID - int
           @DeviceModel , -- DeviceModel - nvarchar(30)
           GETDATE() , -- CreateDateTime - datetime
           GETDATE() , 
           @CreateUser,
           @UpdateUser
         );
Select SCOPE_IDENTITY();
";

                var sqlParam = new SqlParameter[]
                {
                    new SqlParameter("@TypeID", entity.TypeId),
                    new SqlParameter("@DeviceModel", entity.DeviceModel),
                    new SqlParameter("@CreateUser", entity.CreateUser),
                    new SqlParameter("@UpdateUser", entity.UpdateUser),
                };
                return(Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, sqlParam)));
            }
        }
コード例 #2
0
        public static bool UpdateModel(DeviceModelEntity entity)
        {
            using (var con = new SqlConnection(ConnStr))
            {
                var sql = @"
 UPDATE Configuration.dbo.tbl_DeviceModel
 SET TypeID =@typeId ,DeviceModel = @deviceModel ,UpdateDateTime = GETDATE(),  UpdateUser = @UpdateUser
 WHERE PKID = @Pkid
";

                var sqlParam = new SqlParameter[]
                {
                    new SqlParameter("@typeId", entity.TypeId),
                    new SqlParameter("@deviceModel", entity.DeviceModel),
                    new SqlParameter("@UpdateUser", entity.UpdateUser),
                    new SqlParameter("@Pkid", entity.PKID),
                };

                return(SqlHelper.ExecuteNonQuery(con, CommandType.Text, sql, sqlParam) > 0);
            }
        }