Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MySQL C#4.0
 
public void pripass2()
        {
            float  b = 0.5f;
            float  c;
            ppass = Convert.ToSingle (label19.Text);
            try
            {
                if (ppass > 0 && checkBox5.Checked == true)
                {
                    ppass--;
                    label19.Text = ppass.ToString();
                    cmd = new MySqlCommand();
                    cmd.CommandText = "update emppassdetails set activepass='" + label19.Text + "'";
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();
 
                }
                else if (ppass > 0 && checkBox5.Checked == false)
                {
                    c = ppass - b;
                    label19.Text = c.ToString();
                    cmd = new MySqlCommand();
                    cmd.CommandText = "update emppassdetails set activepass='" + label19.Text + "'";
                    cmd.Connection = con;
                    cmd.ExecuteNonQuery();
 
                }
            
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please Call Anurag"+ex.Message );
            }
        }
 
Here PPASS IS declared globally and other variables are local but elseif statement is giving error and if statement is working fine
Data Truncated for column activepass at row 1
Posted 30-Aug-12 22:29pm
Comments
Mohibur Rashid at 31-Aug-12 4:35am
   
where is the condition or limit in your update sql? besides what is the length of activepass in your database?
onurag19 at 31-Aug-12 4:37am
   
how to give that please guide me
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hi friend you should read this,
 
The problem is that those empty values are interpeted as empty strings (''), not as NULL values. 
 
To force a NULL value into those fields you can change your text-file and use the escape character "\N".
 
http://stackoverflow.com/questions/1704304/what-is-this-error-database-query-failed-data-truncated-for-column-column-na[^]
 

http://dba.stackexchange.com/questions/4091/data-truncated-for-column[^]
 
see this Example:
 
mysql> create table a (a float not null);
Query OK, 0 rows affected (0.11 sec)
 
mysql> insert a values ('');
Query OK, 1 row affected, 1 warning (0.05 sec)
 
mysql> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1265 | Data truncated for column 'a' at row 1 |
+---------+------+----------------------------------------+
1 row in set (0.00 sec)
 
mysql> set sql_mode = 'STRICT_ALL_TABLES';
Query OK, 0 rows affected (0.02 sec)
 
mysql> insert a values ('');
ERROR 1265 (01000): Data truncated for column 'a' at row 1
 
regards
sarva
  Permalink  
v4
Comments
onurag19 at 31-Aug-12 4:55am
   
can u give me some more examples please
Sarrrva at 31-Aug-12 5:20am
   
otherwise Refer this Link:
http://www.desknow.com/kb/idx/11/175/article/
Sarrrva at 31-Aug-12 5:14am
   
post your table structure onurag
onurag19 at 31-Aug-12 5:43am
   
CREATE TABLE `emppassdetails` (
`pfno` varchar(20) default NULL,
`activepass` float default '0',
`blockedpass` float default '0',
`borrowedpass` float default '0',
`activepto` float default '4',
`blockedpto` float default '0',
`borrowedpto` float default '0',
`activeschoolpass` float default '3',
`year` int(11) default NULL,
`approved` varchar(5) default 'no'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Sarrrva at 31-Aug-12 5:53am
   
activepass is a float data type, please correct Your Query Syntax or don't try to store Empty String etc.....
 

Write your command text like this
 
"update emppassdetails set activepass=" + Convert.toDecimal(label19.Text) + "";
onurag19 at 31-Aug-12 6:01am
   
its stil giving error
Sarrrva at 31-Aug-12 6:04am
   
What Error?
onurag19 at 31-Aug-12 6:31am
   
data truncated
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Data Truncate for the column (eg: id) error :
Answer: Check Your Data Type weather it support Varchar ()
 
Regards
SHEIK ANAS
  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 756
1 OriginalGriff 345
2 Magic Wonder 131
3 Kishore Pogaru 130
4 Fredrik Bornander 130
0 OriginalGriff 5,705
1 Sergey Alexandrovich Kryukov 4,763
2 CPallini 4,570
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 12 Feb 2014
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