日期:2014-05-18  浏览次数:20925 次

简单很代码,现象很诡异...
代码很简单,只要点button1,能按输入t_1.Text的货号,在表里查找记录,并赋予t_2,t_3,t_4,t_5,t_6值。没有则不显示。
头一次点button1是正常的,如果有记录就返回以上的信息,如果没有就显示空白。但是如果第一次输入的货号有记录,再输入任何货号都是显示上一条信息,哪怕t1.Text=""也是这样,实在是很诡异。
也在t_1.Text的change事件中清空了所有文本框。如图:头一张是正常的,二张明显货号就是空的(就算乱输入也一样)。竟然显示和第一张一样。请各位高人帮忙分析下原因
C# code

类文件:
 public class goods
    {
        int save_flag = 0;//取得是否有记录
        string goods_name = "";//品名
        string goods_place ="";//产地
        string goods_type ="";//型号
        string goods_unit = "";//单位
        string goods_price = "";//价格
        
        //数据库里是否有此商品,0没有、1有
        public int save_flags
        {
            get
            {
                return save_flag;
            }
            set
            {
                save_flag = value;
            }
        }
        
        //商品名
        public string g_name
        {
            get
            {
                return goods_name;
            }
            set
            {
                goods_name = value;
            }
        }

        //商品产地信息
        public string g_place
        {
            get
            {
                return goods_place;
            }
            set
            {
                goods_place = value;
            }
        }

        //商品规格信息
        public string g_type
        {
            get
            {
                return goods_type;
            }
            set
            {
                goods_type = value;
            }
        }

        //商品单位信息
        public string g_unit
        {
            get
            {
                return goods_unit;
            }
            set
            {
                goods_unit = value;
            }
        }

        //商品价格信息
        public string g_price
        {
            get
            {
                return goods_price;
            }
            set
            {
                goods_price = value;
            }
        }

        //搜索商品的信息
        public string goods_find(string goods)
        {
            string goods_finds = "select  * from p_goods where goods_nums = '" + goods + "'";
            m_sql_conn m_conn = new m_sql_conn();
            SqlConnection conn = new SqlConnection(m_conn.sql_conn());
            SqlCommand cmd = new SqlCommand(goods_finds, conn);
            try
            {
                conn.Open();
            }
            catch (System.Exception)
            {
                MessageBox.Show("数据库打开失败", "提示");
                return "GF0000001错误";
            }
            SqlDataReader goods_rs = cmd.ExecuteReader();
            if(goods_rs.Read())
            {
                goods_name =  goods_rs["goods_name"].ToString();
                goods_place = goods_rs["goods_place"].ToString();
                goods_type =  goods_rs["goods_type"].ToString();
                goods_unit =  goods_rs["goods_unit"].ToString();
                goods_price = goods_rs["goods_price"].ToString();
                save_flag = 1;
            }
            conn.Close();
            goods_rs.Close();
            return goods;
        }


调用类
C# code

private void button1_Click(object sender, EventArgs e)
        {
            mygoods.goods_find(t_1.Text.Trim());
            //按t_1.Text查找记录,按货号搜索
            save_yn = mygoods.save_flags;
            //得到结果是否找到,有返回1,没有返回0
            t_2.Text = mygoods.g_name.ToString();
            t_3.Text = mygoods.g_place.ToString();
            t_4.Text = mygoods.g_type.To