Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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();
 
Posted 1-Jan-13 3:18am
Edited 1-Jan-13 4:06am
v4
Comments
Kiran Susarla at 1-Jan-13 9:56am
   
So what is the problem here?
selva_1990 at 1-Jan-13 9:58am
   
numericUpDown1.Value = dr["baleq"].ToString(); in this line Cannot implicitly convert type 'string' to 'decimal'
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
The problem is here:
  numericUpDown1.Value = dr["baleq"].ToString();
Change it into:
  numericUpDown1.Value = Convert.ToDecimal(dr["baleq"]);
 
[EDIT]
 
Because the value isn't changing, try changing
if (dr.Read())
into
while (dr.Read());
 
Hope this helps.
  Permalink  
v2
Comments
selva_1990 at 1-Jan-13 10:11am
   
error gone but value not updating
ProgramFOX at 1-Jan-13 10:15am
   
I updated my answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 458
1 OriginalGriff 344
2 George Jonsson 233
3 Animesh Datta 130
4 Shemeemsha RA 128
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100