当前位置:编程学习 > C#/ASP.NET >>

急,求帮助!就是通过判断数据库某个值是否为空来设定button可用与否

如题,下面是代码,我试了很多次了,不管什么情况下,它都是灰色的,基本上没有判断的作用。请指教啊~~~~~~~ 
//通过病人ID查找出该病人的电子病历信息
        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox8.Text.Trim() == "")
            {
                MessageBox.Show("请输入需要查询的病人ID!", "提示");
                return;
            }
            else 
            {
                try
                {
                    RefreshData1();//显示病人信息
                    RefreshData2();//显示电子病历内容
                }
                catch (Exception ex)
                {
                    //SQL.cn.Close();
                    MessageBox.Show(ex.Message);
                }
            }
            string sconnStr = "server=.;database=project;Integrated Security=true";
            SqlConnection con = new SqlConnection(sconnStr);
            string cmd = "select qrqm from DZBL where brid='" + textBox8.Text.Trim() + "'";
            SqlCommand comd = new SqlCommand(cmd,con);
            con.Open();
            SqlDataReader myDR = comd.ExecuteReader();
            while (myDR.Read())
            {
                if (myDR["qrqm"] != System.DBNull.Value)
                {
                    this.button3修改.Enabled = false;
                    label53.Text = "该病历已经签名确认,不能再作修改";
                }
                else if (myDR["qrqm"] != null)
                {
                    this.button3修改.Enabled = false;
                    label53.Text = "该病历已经签名确认,不能再作修改";
                }
                else
                {
                    this.button3修改.Enabled = true;
                }
            }
            //string QRQM = "select qrqm from DZBL where brid='" + textBox8.Text.Trim() + "'";
            //if (QRQM == "")
            //{ this.button3修改.Enabled = false;
            //  label53.Text = "该病历已经签名确认,不能再作修改"; 
            //}
            //else
            //{
            //    this.button3修改.Enabled = false;
            //}
            //label53.Text = "该病历已经签名确认,不能再作修改"; 
            textBox8.Text = "";
        }
--------------------编程问答--------------------
引用楼主  的回复:
如题,下面是代码,我试了很多次了,不管什么情况下,它都是灰色的,基本上没有判断的作用。请指教啊~~~~~~~ 
//通过病人ID查找出该病人的电子病历信息
  private void button5_Click(object sender, EventArgs e)
  {
  if (textBox8.Text.Trim() == "")
  {
  MessageBox.Show……

我是想通过判断“确认签名”是否为空,如果为空的话,“修改”按钮可用,否则不可用。 --------------------编程问答-------------------- 用存储过程呗,在查询的时候用查询qrqm是否存在,然后给返回值,程序这面根据接收的返回值设置 button的enable属性 --------------------编程问答-------------------- 字段qrqm的数据类型是啥 --------------------编程问答--------------------
引用 2 楼  的回复:
用存储过程呗,在查询的时候用查询qrqm是否存在,然后给返回值,程序这面根据接收的返回值设置 button的enable属性

已经搞定了,呵呵,辛苦各位啦!
 private void button5_Click(object sender, EventArgs e)
        {         
            if (textBox8.Text.ToString() =="")
            {
                MessageBox.Show("请输入需要查询的病人ID!", "提示");
                return;
            }    
            else
                {
                    try
                    {
                        RefreshData1();
                        RefreshData2();
                        if (textBox9.Text.Trim() == "")//判断修改能否使用
                        {
                            button3修改.Enabled = true;   
                        }
                        else
                        {
                            button3修改.Enabled = false;
                            MessageBox.Show("该病历已经确认签名,不可修改!请停止对该病历的操作!", "提示");
                        }
                    }
                    catch (Exception ex)
                    {
                        SQL.cn.Close();
                        MessageBox.Show(ex.Message);
                    }
                }
            textBox8.Text = "";
        }
         --------------------编程问答-------------------- 帮不了你 不知道
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,