如何将字符串转换为numericupdown的十进制 [英] how to convert string to decimal of numericupdown

查看:221
本文介绍了如何将字符串转换为numericupdown的十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

while (dr.Read())
                {
                    //s1 = dr[0].ToString();
                    s2 = dr[1].ToString();
                    s3 = dr[4].ToString();
                    s4 = dr[5].ToString();
                    s5 = dr[6].ToString();

                    flag = 1;

                }
                if (flag == 1)
                {


                    textBox3.Text = s2;
                    textBox4.Text = s3;
                    textBox5.Text = s4;
                    numericUpDown1.Value = s5;
                    MessageBox.Show("found");
                }



}



此代码我写的是从数据库中获取详细信息并获取它们以新的形式进行修改,但是数据库中整数类型的数值减少的数量不是以新的形式出现的。请帮助我..


}

This code i am writing to fetch the details from database and get them in new form and do modification but quantity which is numericupdown of integer type in database is not coming in new form . Please help me..

推荐答案

而不是:

Instead of this:
s5 = dr[6].ToString();



试试这个:


Try this:

s5 = dr.GetInt32(6);



您还需要更改<$ c的类型$ c> s5 从字符串 int



如果数据库中的值不是int,而是double,请使用 GetDouble ,如果值是小数,请使用<$程序基础解决方案之上的c $ c> GetDecimal 。


You also need to change the type of s5 from string to int.

If the value in the database is not an int, but a double, use GetDouble, and if the value is a decimal, use GetDecimal.


....



另一个简单而常见的方式就像



on top of ProgramFox solution....

another simple and common way is like

numericUpDown1.Value =  Convert.ToDecimal( s5);


这篇关于如何将字符串转换为numericupdown的十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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