C# winform

博客园 联系 订阅 管理
  10 Posts :: 1 Stories :: 8 Comments :: 0 Trackbacks

2011年1月17日 #

(1)日期转换

1. Select CONVERT(varchar(100), GETDATE(), 0)    //01 17 2011  8:46AM
2. Select CONVERT(varchar(100), GETDATE(), 1)    //01 17 2011  8:46AM

3. Select CONVERT(varchar(100), GETDATE(), 2)    //11.01.17

4. Select CONVERT(varchar(100), GETDATE(), 3)    //17/01/11
5. Select CONVERT(varchar(100), GETDATE(), 4)    //17.01.11

6. Select CONVERT(varchar(100), GETDATE(), 5)    //17-01-11

7. Select CONVERT(varchar(100), GETDATE(), 6)    //17 01 11

8. Select CONVERT(varchar(100), GETDATE(), 7)    //01 17, 11

9. Select CONVERT(varchar(100), GETDATE(), 8)    //08:50:44

10. Select CONVERT(varchar(100), GETDATE(), 9)    //01 17 2011  8:51:08:793AM

11. Select CONVERT(varchar(100), GETDATE(),10)    //01-17-11

12. Select CONVERT(varchar(100), GETDATE(),11)    //11/01/17

13. Select CONVERT(varchar(100), GETDATE(),12)    //110117

14. Select CONVERT(varchar(100), GETDATE(),13)    //17 01 2011 08:53:18:340

15. Select CONVERT(varchar(100), GETDATE(),14)    //08:54:16:607

16. Select CONVERT(varchar(100), GETDATE(),20)    //2011-01-17 08:55:07

17. Select CONVERT(varchar(100), GETDATE(),21)    //2011-01-17 08:56:03.623

18. Select CONVERT(varchar(100), GETDATE(),22)    //01/17/11  8:56:31 AM

19. Select CONVERT(varchar(100), GETDATE(),23)    //2011-01-17

20. Select CONVERT(varchar(100), GETDATE(),24)    //09:03:36

21. Select CONVERT(varchar(100), GETDATE(),25)    //2011-01-17 09:03:55.950
22. Select CONVERT(varchar(100), GETDATE(),100)    //01 17 2011  9:04AM

23. Select CONVERT(varchar(100), GETDATE(),101)    //01/17/2011

24. Select CONVERT(varchar(100), GETDATE(),102)    //2011.01.17
25. Select CONVERT(varchar(100), GETDATE(),103)    //17/01/2011

26. Select CONVERT(varchar(100), GETDATE(),104)    //17.01.2011

27. Select CONVERT(varchar(100), GETDATE(),105)    //17-01-2011

28. Select CONVERT(varchar(100), GETDATE(),106)    //17 01 2011

29. Select CONVERT(varchar(100), GETDATE(),107)    //01 17, 2011

30. Select CONVERT(varchar(100), GETDATE(),108)    //09:17:03

31. Select CONVERT(varchar(100), GETDATE(),109)    //01 17 2011  9:17:23:280AM

32. Select CONVERT(varchar(100), GETDATE(),110)    //01-17-2011

33. Select CONVERT(varchar(100), GETDATE(),111)    //2011/01/17

34. Select CONVERT(varchar(100), GETDATE(),112)    //20110117

35. Select CONVERT(varchar(100), GETDATE(),113)    //17 01 2011 09:18:33:560
36. Select CONVERT(varchar(100), GETDATE(), 114)          //09:19:03:560
37. Select CONVERT(varchar(100), GETDATE(),120)    //2011-01-17 09:20:16
38. Select CONVERT(varchar(100), GETDATE(),121)    //2011-01-17 09:20:35.000

39. Select CONVERT(varchar(100), GETDATE(),126)    //2011-01-17T09:21:32.750
40. Select CONVERT(varchar(100), GETDATE(),130)    //12 ??? 1432  9:22:10:043AM

41. Select CONVERT(varchar(100), GETDATE(),131)    //12/02/1432  9:22:32:450AM

 

(2)时间差 DATEDIFF(datepart,startdate,enddate)

datepart 缩写
yy, yyyy
季度 qq, q
mm, m
年中的日 dy, y
dd, d
wk, ww
星期 dw, w
小时 hh
分钟 mi, n
ss, s
毫秒 ms
微妙 mcs
纳秒 ns

(3)时间相加  DateAdd( date-part, span-date, date-expression ):

例:select DateAdd(month ,10,getdate())

 date-part:year | quarter | month | week | day | hour | minute | second | millisecond

 


 

posted @ 2011-01-17 09:26 fffdc 阅读(131) 评论(0) 编辑

2010年11月24日 #

1.引入 AjaxPro.2.dll

2.在web.config文件中的<system.web>

 <httpHandlers>
   <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, Ajaxpro.2"/>
  </httpHandlers

基本设置已完成

使用

3.前台

<script>
    function CheckUser()
    {
        var result=Login.isRight('admin','123456');
        alert(result.value);
    }
    </script>

<input type="button" value="testajax" onclick="CheckUser()" />

4.后台

    4.1

  protected void Page_Load(object sender, EventArgs e)
    {
        //注册ajax
        if(!Page.IsPostBack)
        {
         AjaxPro.Utility.RegisterTypeForAjax(typeof(Login));
        }
      
    }

  4.2

  //判断用户名密码是否正确
    [AjaxPro.AjaxMethod]

  public int isRight(string userName, string userPwd)
    {
        int count = 0;
        try
        {
            count = bll.Exists(userName,userPwd);
        }
        catch (Exception)
        {

            throw;
        }
        return count;
    }

 

posted @ 2010-11-24 16:35 fffdc 阅读(109) 评论(0) 编辑

2010年8月23日 #

 

provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接

解决方案:

所有程序->Ms Sql Server->配置工具->sql server外围应用配置器->服务和连接的外围应用配置器->打开MSSQLSERVER节点下的Database Engine 节点,先择"远程连接",接下建议选择"同时使用TCP/IP和named pipes",确定后,重启数据库服务就可以了.

 

当同时出现microsoft sql server 2005 错误53

最有可能的原因是你修改了计算机的名称,

解决方案:

重新选择数据库引擎就ok了

posted @ 2010-08-23 09:47 fffdc 阅读(2534) 评论(0) 编辑

2010年3月24日 #

 /// <summary>
        /// 执行多条SQL语句,实现数据库事务。
        /// </summary>
        /// <param name="SQLStringList">多条SQL语句</param>  
        public int ExecuteSqlTran(List<String> SQLStringList)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                SqlTransaction tx = conn.BeginTransaction();
                cmd.Transaction = tx;
                try
                {
                    int count = 0;
                    for (int n = 0; n < SQLStringList.Count; n++)
                    {
                        string strsql = SQLStringList[n];
                        if (strsql.Trim().Length > 1)
                        {
                            cmd.CommandText = strsql;
                            count += cmd.ExecuteNonQuery();
                        }
                    }
                    tx.Commit();
                    return count;
                }
                catch
                {
                    tx.Rollback();
                    return 0;
                }
            }
        }

///

create procedure [dbo].[p_suspend_business] 

03    @Bfixednum  varchar(40)
04 as
05 begin transaction
06   
07   declare @SNumber int
08   declare @messageNumber int
09   select @SNumber=SNumber from sendnumber where Bfixednum=@Bfixednum
10   select @messageNumber = count(@Bfixednum) from [message] where Bfixednum = @Bfixednum and mDate between (select  dateadd(dd,-day(getdate())+1,getdate()))  and   (select  dateadd(dd,-day(getdate()),dateadd(m,1,getdate())))
11   
12   
13   --参数检查
14   if (@SNumber is null or @messageNumber = '')
15     begin
16       raiserror('错误!缺少参数 ,请检查!',16,1)
17       rollback
18       return
19     end
20     
21   if (@messageNumber >= @SNumber)
22     begin
23      update dbo.Business set BState=0 where  Bfixednum=@Bfixednum
24    commit transaction    
25     end
26   
27 GO
来源

 

posted @ 2010-03-24 16:54 fffdc 阅读(504) 评论(2) 编辑

2009年10月14日 #

需要引入命名空间:
using Microsoft.Win32;
       /// 读注册表中指定键的值
        /// </summary>
        /// <param name="key">键名</param>
        /// <returns>返回键值</returns>
        public static string ReadReg(string key)
        {
            string temp = "";
            try
            {
                RegistryKey key = Registry.LocalMachine;                      //Registry参数自己选择
                RegistryKey subKey = Key.OpenSubKey("SOFTWARE\\Exobo");      //注册表位置
                temp = subKey.GetValue(key).ToString();
                subKey.Close();
                key .Close();
                return temp;
            }
            catch (Exception)
            {
                throw;
            }
        }
       /// <summary>
        /// 创建目录(第一次注册)---写入
       /// </summary>
       /// <param name="username"></param>
       /// <param name="password"></param>
       /// <param name="userType">版本类型</param>
       /// <param name="userMax">最大试用次数</param>
       /// <param name="userTime">当前试用次数</param>
       /// <returns></returns>
        public static bool CreateReg(string username,string password,string userType,string userMax,string userTime)
        {
            bool temp = false;
            try
            {
                RegistryKey Key = Registry.LocalMachine;
                RegistryKey subKey = Key.OpenSubKey(@"SOFTWARE\Exobo");
                //未注册 从新创建
                if (subKey == null)
                {
                    Key.CreateSubKey("SOFTWARE\\Exobo");
                }
              //修改注册信息
                subKey = Key.OpenSubKey("SOFTWARE\\Exobo", true);
                subKey.SetValue(username, password);
                subKey.SetValue(username + "Type", userType);
                subKey.SetValue(username + "Time", userTime);
                subKey.SetValue(username + "Max", userMax);             
                temp = true;
                subKey.Close();
                Key.Close();
                return temp;

            }
            catch (Exception)
            {
                throw;
            }

        }
   //判段是否有该项
        public static bool HaveReg()
        {
            bool temp = false;
            try
            {
                RegistryKey Key = Registry.LocalMachine;
                RegistryKey subKey = Key.OpenSubKey(@"SOFTWARE\Exobo");
                //未注册 从新创建
                if (subKey == null)
                {
                    temp = false;
                }
                else
                {
                    temp = true;
                }
                subKey.Close();
                Key.Close();
                return temp;
            }
            catch (Exception)
            {
                throw;
            }

        }
      
posted @ 2009-10-14 14:09 fffdc 阅读(306) 评论(0) 编辑

2009年9月15日 #

摘要: 输入时自动匹配AutoCompleteStringCollection myCutomSource = new AutoCompleteStringCollection(); myCutomSource.AddRange(new string[] { "上海市某区", "北京市某区", "天津市某区", "重庆市某区" }); this.textBox1.AutoCompleteSource = ...阅读全文
posted @ 2009-09-15 14:25 fffdc 阅读(145) 评论(1) 编辑

2009年9月8日 #

摘要: private void button2_Click(object sender, EventArgs e) { bool have = false; foreach (TabPage a in tabControl1.TabPages) { if (a.Name == "KKK")//tabpage名 kkk { have = true; } } if (!have) { TabPage Ta...阅读全文
posted @ 2009-09-08 17:23 fffdc 阅读(1069) 评论(2) 编辑

2009年8月29日 #

摘要: ///默认开始添加的节点为根节点DataTable dt = new DataTable(); private void bindtree(TreeNode addFather, string father) { DataRow[] drs = null; if (father != null && father != "") { drs = dt.Select("FatherNo...阅读全文
posted @ 2009-08-29 20:54 fffdc 阅读(426) 评论(2) 编辑

2009年8月18日 #

摘要: //////让所有列都显示出来 ///将最后一列的 AutoSizeMode 属性设置为 Fill,并对其他列使用其他调整大小选项。如果其他列使用了过多的可用空间,可设置最后一列的 MinimumWidth属性。设定背景颜色 ------------交替行样式this.dataGridView2.RowsDefaultCellStyle.BackColor = Color.Bisque; //默认...阅读全文
posted @ 2009-08-18 20:31 fffdc 阅读(967) 评论(1) 编辑

2009年8月10日 #

摘要: 当在一个combobox1中选择某一项号,另一个combobox2中也跟着变化 做法如下:load()事件DAL.ProjectCollection c = DAL.DB.Select().From(DAL.Project.Schema).ExecuteAsCollection<DAL.ProjectCollection>(); comboBox1.DisplayMember = DA...阅读全文
posted @ 2009-08-10 12:17 fffdc 阅读(661) 评论(0) 编辑