[置顶] c# 条件编译

摘要: c# 编程中常常会碰到如下问题: 一段代码,在开发环境上需要编译,在生产环境部署时需要注释掉。 这时候条件编译时很好的选择。如下,Debug 和 Release 模式下不相同。using System;namespace ConditionalCompilation{ class Program { static void Main(string[] args) { Trace.ShowMessage("Starting"); Console.WriteLine("Running------"); ... 阅读全文

posted @ 2014-02-18 12:30 天蝎座筷子 阅读(212) 评论(0) 推荐(0) 编辑

2014年4月1日

Log输出

摘要: 1 using System.IO; 2 using System; 3 public class OutputLog 4 { 5 #region 添加Log 6 public static string logFilePath = System.Configuration.ConfigurationSettings.AppSettings["LogFile"].ToString(); 7 private static void AppendLogs(string logMessage) 8 { 9 try10 {11 ... 阅读全文

posted @ 2014-04-01 16:43 天蝎座筷子 阅读(185) 评论(0) 推荐(0) 编辑

SqlHelper

摘要: 1 using System.Configuration; 2 using System.Data; 3 using System.Data.SqlClient; 4 5 namespace SqlHelper 6 { 7 class SqlHelper 8 { 9 //创建App.config10 //11 // 12 //13 //References 引用System.Configuration14 private static string connString =... 阅读全文

posted @ 2014-04-01 16:28 天蝎座筷子 阅读(142) 评论(0) 推荐(0) 编辑

读取Excel得到DataTable

摘要: 1 using Microsoft.Office.Interop.Excel; 2 using System; 3 using System.Data; 4 using System.Diagnostics; 5 6 namespace ExcelToData 7 { 8 public class ExcelHelper 9 { 10 private static Stopwatch wath = new Stopwatch(); 11 12 /// 13 /// 使用COM读取Excel 14 ... 阅读全文

posted @ 2014-04-01 16:25 天蝎座筷子 阅读(215) 评论(0) 推荐(0) 编辑

WinForm 中使用OpenFileDialog

摘要: 1 using Microsoft.Win32; 2 3 namespace WpfApplication1 4 { 5 class WPFOpenFileDialog 6 { 7 public void OpenFile() 8 { 9 OpenFileDialog openFileDialog = new OpenFileDialog();10 openFileDialog.InitialDirectory = "D:"; // 初始化地址11 openFileDia... 阅读全文

posted @ 2014-04-01 16:21 天蝎座筷子 阅读(202) 评论(0) 推荐(0) 编辑

2014年2月25日

项目间调用UserControl

摘要: 工作中(c#)我们经常碰到这样的情况:写了一个UserControl,但是在另一个项目需要调用这个UserControl下列两种方法可以实现1. 1)将控件完全写在.cs文件中:创建一个UserControl,然后在后台文件中写控件,如下 1 protected void Page_Load(object sender, EventArgs e) 2 { 3 string logoutUrl = ConfigurationManager.AppSettings["Logout"].ToString(); 4 Li... 阅读全文

posted @ 2014-02-25 17:30 天蝎座筷子 阅读(254) 评论(0) 推荐(0) 编辑

2014年2月21日

MSBuild、条件编译、预处理命令

摘要: MSBuildMSBuild可以快速的将程序编译成可部署文件:命令行进入MSBuild文件夹 :cdC:\Windows\Microsoft.NET\Framework64\v4.0.30319编译程序:MSBuild F:\xxx\xxx.xml /t:TEST /p:DefineConstants=TEST条件编译:1 2 3 4 5 6 7 8 9 具体可参考:http://www.infoq.com/cn/articles/MSBuild-1代码: 1 using System; 2 namespace MSBuildTest 3 { 4 cla... 阅读全文

posted @ 2014-02-21 17:04 天蝎座筷子 阅读(1002) 评论(0) 推荐(0) 编辑

2013年12月3日

批量数据插入SqlBulkCopy

摘要: 1 //批量数据插入 SqlBulkCopy 2 public void UsingSqlBulkCopy() 3 { 4 using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connStr)) 5 { 6 bulkCopy.DestinationTableName = "Users"; 7 bulkCopy.ColumnMappings.Add("Name", "UserName");//DataTable中... 阅读全文

posted @ 2013-12-03 09:51 天蝎座筷子 阅读(199) 评论(0) 推荐(0) 编辑

2013年11月29日

WPF 双向绑定

摘要: 定义类: 类实现INotifyPropertyChanged 接口 1 using Microsoft.Win32; 2 using System.ComponentModel; 3 using System.Windows; 4 5 namespace WPFEntity 6 { 7 public class Person : INotifyPropertyChanged 8 { 9 private int age;10 11 public event PropertyChangedEventHandler PropertyChanged;1... 阅读全文

posted @ 2013-11-29 16:16 天蝎座筷子 阅读(418) 评论(0) 推荐(0) 编辑

编程思想之一

摘要: 编程思想:编程时要对“不可能发生的情况” 做处理!这是一个编程的好习惯。 如: 在编写登陆时 1 public void LogOn(string userName) 2 { 3 DataSet dataSet = SqlHelper.ExecuteDataSet( 4 "select * from users where username=@UserName", new SqlParameter("@UserName", userName)); 5 DataTable tabl... 阅读全文

posted @ 2013-11-29 15:33 天蝎座筷子 阅读(141) 评论(0) 推荐(0) 编辑

导航