如何在ado.net中创建生日提醒 [英] How to create Birthday reminder in ado.net

查看:71
本文介绍了如何在ado.net中创建生日提醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



我正在创建一个有一个任务的应用程序,即显示多个患者生日提醒。

那个意味着提醒应该在该特定日期显示多个患者姓名。

患者姓名应该在一个标签中显示为逗号分隔,假设17/01/2013是两个患者的生日,那么它应该显示为生日快乐toJohn,Ricky。​​

我希望你能说明我实际上想说的是我在表单加载时编写了这段代码,但是它没有用。

Hello friends,

I am creating an application which has one task and that is to show multiple patient birthday reminders.
That means reminders should show multiple patient names on that particular date.
Patient name should show like comma separated in one label, suppose 17/01/2013 is the birthday off two patient then it should show like Happy Birthday to "John, Ricky".
I hope you are getting my point what I am actually trying to say I wrote this code in form load, but it not working.

con = new SqlConnection("Data Source=ADMIN\\SQLEXPRESS;Initial Catalog=PhysioCure; Integrated Security=true");
            con.Open();
            DateTime dtmain = System.DateTime.Now;
            cmd = new SqlCommand("select PationName,ContactNo from Physio_cureTable where DateOfBirth like '" + dtmain.Date.ToString().Substring(0, 5) + "%'", con);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                label18.Name = reader.GetInt32(0).ToString();
                label18.Text = reader.GetString(3).ToUpper();
                label19.Text = reader.GetString(5).ToUpper();

            }
            reader.Close();
            con.Close();

推荐答案

1。您的select语句返回2列。在阅读时,你假设它有6(你的索引要到5)。

2.你正在为label18设置名称属性。您应该设置Text属性。

3.您需要将名称附加到Text属性。当前逻辑将仅显示姓氏。

4.您在应用程序中使用日期作为字符串。这是不正确的。有一个 DateTime 数据类型,您必须使用它。
1. Your select statement returns 2 columns. While reading, you assume it has 6 (Your index goes till 5).
2. You are setting Name property for label18. You should be setting Text property.
3. You need to append names to Text property. Current logic will display only the last name.
4. You are using dates as string in your application. This is not correct. There is a DateTime datatype and you must use it.


这篇关于如何在ado.net中创建生日提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆