摘要: SqlConnection conn=null;try{ PrepareEverionment(); conn = new SqlConnection(); conn.ConnectionString = "..................."; conn.Open();}finally{ conn.Close();}这段代码问题是:如PrepareEverionment()发生异常时,conn就任然为null在执行finally中代码时就会出异常,应该用using这样在using中会自动判断conn是否为null 阅读全文
posted @ 2014-04-10 11:39 xjt360 阅读(114) 评论(0) 推荐(0) 编辑
摘要: class A{ public A() { PrintFields(); } public virtual void PrintFields(){}}class B:A{ int x=1; int y; public B() { y=-1; } public override void PrintFields() { Console.WriteLine("x={0},y={1}",x,y); }}在new B()时输出结果是1,0因为一个类在new时是先初始化字段在初始化构造函数,在初始化构造函数时先初始化父类的构造函数 阅读全文
posted @ 2014-04-10 10:41 xjt360 阅读(107) 评论(0) 推荐(0) 编辑
摘要: abstract class BaseClass{ public virtual void MethodA(){Console.WriteLine("BaseClass");} public virtual void MethodB(){}}class Class1:BaseClass { public void MethodA(){Console.WriteLine("Class1");} public override void MethodB(){}}class Class2:Class1 { new public void MethodB()}c 阅读全文
posted @ 2014-04-10 10:19 xjt360 阅读(107) 评论(0) 推荐(0) 编辑
摘要: select top 1*from table1 order by id descselect * from table1where id=(select max(id) from table1)第一条查询语句比较好 阅读全文
posted @ 2014-04-10 09:52 xjt360 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 这两个的区别正像DataSet和DataReader的区别,XDocument是全部生成对像加载到内存中,而XmlReader是像流一样一点一点的读。所以在读大数据时用XReader这样就不会把服务器的内存占爆XDocument xdoc=XDocument.load(@"c:\1.xml");XElement xeRoot=xdoc.Root;foreach(XElement xePerson in xeRoot.Elements()){XElement xeName=xePerson.Element("Name");string name=xeNna 阅读全文
posted @ 2014-04-10 08:19 xjt360 阅读(235) 评论(0) 推荐(0) 编辑