在numericupdown控件中从数据库获取值(帮帮我) [英] getting value from database in numericupdown control (help me)

查看:290
本文介绍了在numericupdown控件中从数据库获取值(帮帮我)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UGIcon.Open();
            cmd = new SqlCommand("select * from purchase where cm='" + toolStripTextBox1.Text + "'", UGIcon);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
               first 4 lines fetching data from database while executing but in numericupdown it showing error 
                textBox1.Text = dr["cm"].ToString();
                textBox2.Text = dr["om"].ToString();
                textBox3.Text = dr["address"].ToString();
                maskedTextBox1.Text = dr["phone"].ToString();

               numericUpDown1.Value = dr["baleq"].ToString();
            } 
            UGIcon.Close();

推荐答案





问题在于:

Hi,

The problem is here:
numericUpDown1.Value = dr["baleq"].ToString();



将其更改为:


Change it into:

numericUpDown1.Value = Convert.ToDecimal(dr["baleq"]);









因为价值不是不要改变,试着改变





Because the value isn''t changing, try changing

if (dr.Read())



进入


into

while (dr.Read());





希望这有帮助。



Hope this helps.


这是因为你的numericUpDown控件'的value属性是期待一个十进制类型的值,你传递一个字符串。

你可以使用Convert.ToDecimal或Decimal.TryParse,将字符串值转换为十进制并分配它。

Something像这样:

this is because your numericUpDown control''s value property is expecting an decimal type value and you are passing a string.
You can use Convert.ToDecimal or Decimal.TryParse, convert the string value to decimal and assign it.
Something like this:
 decimal number;
 UGIcon.Open();
......
 if (dr.Read())
 {
    .......

     if (Decimal.TryParse(dr["baleq"].ToString(), out number))
     {
        numericUpDown1.Value = number;
     }
 }
 UGIcon.Close();


这篇关于在numericupdown控件中从数据库获取值(帮帮我)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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