摘要: Operator运算符重载与Implicit隐式类型转换class Person { public int Age { get; set; } public string Name { get; set; } public static int operator -(Person p1, Person p2)//int为想减结果类型,-表示对-进行运算符重载 //参数为待计算的两个值 { return p1.Age - p2.Age; }//当重载>后,要求必须重载< public static bool operator >(Person p1, Person p2) { 阅读全文
posted @ 2011-10-06 11:05 _best 阅读(214) 评论(0) 推荐(0) 编辑
摘要: public partial class FormClasses : Form { //1.将构造函数改成 private ,这样,在类的外部就不能够随意创建 班级管理窗体 对象了 private FormClasses() { InitializeComponent(); } //2.声明一个 静态变量,用以保存 当前系统唯一存在的一个 班级管理窗体 对象 static FormClasses formClasses = null; //3.创建一个静态方法,里面 只创建以此 班级管理窗体对象,并将此对象返回 public static FormClasses GetSingle() { / 阅读全文
posted @ 2011-09-08 13:46 _best 阅读(120) 评论(0) 推荐(0) 编辑
摘要: if exists(select * from sys.objects where name='bank')drop table bankCREATE TABLE bank( customerName nvarchar(10), --顾客姓名 [Money] MONEY --当前余额)ALTER TABLE bank --创建表 ADD CONSTRAINT CK_currentMoney CHECK([Money]>=1)INSERT INTO bank(customerName,[Money]) VALUES('张三',1000)INSERT INTO 阅读全文
posted @ 2011-08-28 13:22 _best 阅读(136) 评论(0) 推荐(0) 编辑
摘要: -- charindex 查找第一个参数在第二个参数中的位置 第三个参数起始位置--下标是从1开始的 返回0证明没有找到--里面的参数可以由表的字段来直接代替SELECT CHARINDEX('My','My abc Course',1 )select sname,charindex('张',sname,1) as '张出现的位置' from Student--Len 求字符长度select len('aaa')--求每个人的名字长度select sname,len(sname) as '姓名长度' 阅读全文
posted @ 2011-08-25 22:10 _best 阅读(437) 评论(0) 推荐(0) 编辑
摘要: --把一个表(或结果集)一次插入到数据库表中insert into class(cname,cDescription)select '01-2','01-21' union allselect '01-3','01-22' union allselect '01-4','01-23' union allselect '01-5','01-24' union allselect '01-6','01-25' union allselect 阅读全文
posted @ 2011-08-25 22:07 _best 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 当我们向有自动增涨列的表中添加完数据后,想得到刚刚生成的自动增涨列的值,有两种方法:第一种方法:\cmd.CommandText =“insert into class(cName,cDescription) output inserted.Id values(‘高三一班’,‘描述’)”;第二种方法在sql语句后加上; select @@identity: 阅读全文
posted @ 2011-08-25 21:46 _best 阅读(124) 评论(0) 推荐(0) 编辑
摘要: //在控件的KeyPress事件中private void txtPhoneNo_KeyPress(object sender, KeyPressEventArgs e) { char result=e.KeyChar; if (char.IsDigit(result)||result==8) { e.Handled = false; } else { e.Handled = true; } } 阅读全文
posted @ 2011-08-25 21:40 _best 阅读(248) 评论(0) 推荐(0) 编辑
摘要: DataTable dt = new DataTable();//创建一个DataTable的实例;//写一个简单的SqlHelper public static class SqlHelper { static string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["strConn"].ConnectionString; /// <summary> /// 执行增加、修改、删除操作; /// </summary> /// <param name= 阅读全文
posted @ 2011-08-25 21:36 _best 阅读(1396) 评论(0) 推荐(0) 编辑
摘要: <%@ WebHandler Language="C#" Class="ValidateCode" Debug="true" %>using System;using System.Web;using System.Drawing;using System.Drawing.Imaging;using System.Web.SessionState;//一般处理程序中如果要使用Session必须实现此命名空间里的接口/// <summary>/// 验证码/// </summary>public cl 阅读全文
posted @ 2011-07-29 21:09 _best 阅读(218) 评论(1) 推荐(0) 编辑
摘要: /// <summary> /// 根据商品ID查询出单个商品 /// </summary> /// <param name="productId">商品ID</param> /// <returns></returns> public Entity_B2CSM.Products GetProduct(int productId) { Products product = null; string selectSql = string.Format(@"SELECT [Id] ,[Produc 阅读全文
posted @ 2011-07-29 20:30 _best 阅读(1287) 评论(0) 推荐(0) 编辑