已有56人关注
C#开发典型模块大全中,桌面精灵模块,我改成sql数据库,运行出错,请老师看下是什么问题呀?
发表在C#图书答疑 2010-09-11
是否精华
版块置顶:
//以下写在主窗体中,

        private void frm_main_Load(object sender, EventArgs e)
        {
            timer2.Start();            
        }
  


      //日程提醒,弹出窗口。
        
        private void timer2_Tick(object sender, EventArgs e)
        {
            DataSet myds = dbOp.getDataSet("select * from tb_remind ", "tb_remind");
           
            for (int i = 0; i < myds.Tables[0].Rows.Count; i++)
            {
                string strName = myds.Tables[0].Rows[i][0].ToString();
                string strFrequency = myds.Tables[0].Rows[i][1].ToString();
                string strTime = myds.Tables[0].Rows[i][2].ToString();
                string strContent = myds.Tables[0].Rows[i][3].ToString();
                string[] strTimes = strTime.Split(' ');
                //判断提醒方式,并根据提醒方式弹出提醒对话框
                if (strFrequency == "仅仅一次")
                {
                    if (DateTime.Now.ToShortDateString() == strTimes[0].ToString() && DateTime.Now.ToLongTimeString() == strTimes[1].ToString())
                    {
                        MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    //int intNum = Convert.ToInt32(strFrequency.Substring(0, 1));  [font color=#FF0000] //注释掉这些就没出错,确定这段有问题。[/font]
                    //string strUnit = strFrequency.Substring(1, 1);
                    //TimeSpan TSpan = DateTime.Now - Convert.ToDateTime(strTimes[0]);
                    //switch (strUnit)
                    //{
                    //    case "天"://每几天提醒一次
                    //        if (TSpan.Days % intNum == 0 && DateTime.Now.ToLongTimeString() == strTimes[1].ToString())
                    //            MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //        break;
                    //    case "周"://每几周提醒一次
                    //        if (TSpan.Days % (intNum * 7) == 0 && DateTime.Now.ToLongTimeString() == strTimes[1].ToString())
                    //            MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //        break;
                    //    case "月"://每几月提醒一次
                    //        if (TSpan.Days % (intNum * 30) == 0 && DateTime.Now.ToLongTimeString() == strTimes[1].ToString())
                    //            MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //        break;
                    //    case "年"://每几年提醒一次
                    //        if (TSpan.Days % (intNum * 365) == 0 && DateTime.Now.ToLongTimeString() == strTimes[1].ToString())
                    //            MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //        break;
                    //}
                }
            }
        }



//以下是数据库

_name     char
_frequency  nchar
_time      nchar     数据格式为 2008-06-18 0:00:00 
_content   nchar
_isGq    char
分享到:
精彩评论 5
小科_mrkj
学分:43 LV2
2010-09-13
沙发
读者朋友:
  您好,你插入断点,看一下读取出的数据是否正确.
wufayou
学分:0 LV1
TA的每日心情
第五天
2023-03-18 21:24:17
2010-09-13
板凳

程序自己好了,但是弹出了8个提醒窗口,这是什么原因呀?请老师指导一下呀,谢谢。
小科_mrkj
学分:43 LV2
2010-09-14
地板
读者朋友:
     您好,因为有8条记录都符合条件,所以会弹出8次,这个主要跟数据有关系。
wufayou
学分:0 LV1
TA的每日心情
第五天
2023-03-18 21:24:17
2010-09-14
4L
我的数据库中只有一条记录,不知为什么会出8个确认窗口。
wufayou
学分:0 LV1
TA的每日心情
第五天
2023-03-18 21:24:17
2010-09-18
5L


我搞清楚了,是定时器的时间间隔设得太短了,100加长到1000后就正常了。
首页上一页 1 下一页尾页 5 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照