Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 1-Jan-13 4:06am
v4
Comments
Kiran Susarla 1-Jan-13 9:56am    
So what is the problem here?
selva_1990 1-Jan-13 9:58am    
numericUpDown1.Value = dr["baleq"].ToString(); in this line Cannot implicitly convert type 'string' to 'decimal'

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:
C#
 decimal number;
 UGIcon.Open();
......
 if (dr.Read())
 {
    .......

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

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

Change it into:
C#
numericUpDown1.Value = Convert.ToDecimal(dr["baleq"]);


[EDIT]

Because the value isn't changing, try changing
C#
if (dr.Read())

into
C#
while (dr.Read());


Hope this helps.
 
Share this answer
 
v2
Comments
selva_1990 1-Jan-13 10:11am    
error gone but value not updating
Thomas Daniels 1-Jan-13 10:15am    
I updated my answer.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900