摘要: 在 ASP.NET 中可以非常方便地执行 MD5 或 SHA1 加密。<%@ Import Namespace="System.Web.Security" %>FormsAuthentication.HashPasswordForStoringInConfigFile只需要两步,第一步引入名称空间(该名称空间也可以省略引用),第二步执行加密函数。FormsAuthentication.HashPasswordForStoringInConfigFile 有两个参数:第一个参数是要加密的字符串;第二个参数可选值有 MD5 和 SHA1,表示使用哪种加密方法。返回加 阅读全文
posted @ 2009-12-25 23:20 deepwishly 阅读(192) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using Sy 阅读全文
posted @ 2009-12-25 23:14 deepwishly 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 数据库操作一、最简单的。string connString = "Data Source=(local);Initial Catalog=db;User Id=userId;Password=password";using (SqlConnection conn = new SqlConnection(connString)){ conn.Open(); string sql = @"delete from table1"; using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.ExecuteN 阅读全文
posted @ 2009-12-25 23:10 deepwishly 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 可以把投影、聚合、筛选、排序组合起来使用。int[] arr = { 1, 2, 3, 7, 8, 9, 6, 5, 4 };var items = arr.Where(i => i > 3).OrderBy(i => i);把 > 3 的元素按升序排列,显示为:456789 阅读全文
posted @ 2009-12-25 22:58 deepwishly 阅读(118) 评论(0) 推荐(0) 编辑
摘要: OrderByint[] arr = { 1, 2, 3, 7, 8, 9, 6, 5, 4 };var items = arr.OrderBy(i => i);按 1、2、3……排序。OrderByDescendingint[] arr = { 1, 2, 3, 7, 8, 9, 6, 5, 4 };var items = arr.OrderByDescending(i => i);按 9、8、7……排序。Reverseint[] arr = { 1, 2, 3, 7, 8, 9, 6, 5, 4 };var items = arr.Reverse();倒序,本例中按 4、5、6 阅读全文
posted @ 2009-12-25 22:55 deepwishly 阅读(277) 评论(0) 推荐(0) 编辑
摘要: Whereint[] arr = { 1, 2, 3, 7, 8, 9, 6, 5, 4 };var items = arr.Where(i => i > 3 && i < 8);foreach (var m in items){ Response.Write(m.ToString() + "<br>");}Lambda 表达式 i => i > 3 && i < 8 表示只选择 > 3 且 < 8 的元素,显示为:7654 阅读全文
posted @ 2009-12-25 22:50 deepwishly 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 我们一般说的 LINQ 是指 LINQ 表达式,详见 LINQ 步步学,但除了表达式以外,LINQ 查询操作更方便,凡是实现了接口 IEnumerable<T> 或 IQueryable<T> 的,都可以用 LINQ 查询操作。方法一览int[] arr = { 1, 2, 3, 7, 8, 9, 6, 5, 4 };Response.Write(arr.Count() + "<br>"); // 元素数量,这里为 9Response.Write(arr.Sum() + "<br>"); // 元素总和,这 阅读全文
posted @ 2009-12-25 22:39 deepwishly 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 我们一般说的 LINQ 是指 LINQ 表达式,详见 LINQ 步步学,但除了表达式以外,LINQ 查询操作更方便,凡是实现了接口 IEnumerable<T> 或 IQueryable<T> 的,都可以用 LINQ 查询操作。Selectint[] arr = { 1, 2, 3, 7, 8, 9, 6, 5, 4 };var items = arr.Select(i => i);foreach (var m in items){ Response.Write(m.ToString() + "<br>");}显示:12378965 阅读全文
posted @ 2009-12-25 22:31 deepwishly 阅读(201) 评论(0) 推荐(0) 编辑
摘要: XML 是个好东西,但查询 XML 真的不方便,自从有了 LINQ to XML 后,一切改变了。假设有 XML 文件如下:<?xml version="1.0" encoding="utf-8" ?><company> <name engName="cftea">千一网络</name> <employees> <employee> <name age="29">张龙</name> </employee> & 阅读全文
posted @ 2009-12-25 22:25 deepwishly 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 如果您正在使用 SQL Server 数据库,那么使用 LINQ to SQL 将为您带来极大的方便。首先,在 App_Code 中新建一个“LINQ to SQL 类”项,我们命名为 DataClasses.dbml,并打开它。其次,在数据库资源管理器中连接数据库,并展开“表”,然后将某个/些表(我们这里是 TranTable)拖到 DataClasses.dbml 的界面中,也可以只拖需要的字段,保存 DataClasses.dbml。最后,使用 LINQ 吧,代码如下:DataClassesDataContext dc = new DataClassesDataContext();var 阅读全文
posted @ 2009-12-25 22:14 deepwishly 阅读(146) 评论(0) 推荐(0) 编辑