Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m writing a code in which i have to print true when checkbox is clicked now i've come up with this
bool bResume = chkbResume.Checked;
            MySqlConnection MyCon = new MySqlConnection("server=localhost; Database = nikz; user id=root; password=nikhil; pooling=false;");

            MyCon.Open();

            MySqlCommand command = new MySqlCommand();

 command.Parameters.Add("@resume", bResume);
          
            string SQL = "INSERT INTO LFT_employees (S_no,Emp_no,Name,DOB,Contact,Alternate_Number,DOJ,DOA,Email_id,DOL,Status,P_F_number,Pan_number,Resume) VALUES (@Sno,@EmpNo,@EmpName,@Dob,@Contact,@altno,@DOJ,@DOA,@Email_id,@DOL,@status,@PFno,@pan_no,@resume)";
            command.Connection = MyCon;
            command.CommandText = SQL;
            command.ExecuteNonQuery();
            MyCon.Close();


this prints 1 in column named resume but i want to print true ,how can that be done?????
Posted

Well, mysql has no text valued boolean. Bool fields use 0-1 logic instead, but you don't need to worry about this. You can use char field if you want, but it is a wrong approach. When selesting IF[^] statement can convert int values to string, but this is also not needed. .NET will simply handle all non-zero values as true.
 
Share this answer
 
Comments
nkhldhar 26-Jun-12 4:50am    
it is not soand i need to print true/false or yes/no instead of 0/1 can u help ??? i m using visual c# 2008???
Did you mean you want to insert bool value as string? say true/false?
if so then you need to modify your column type as something which accepts string and do

C#
string bResume = chkbResume.Checked ? bool.TrueString : bool.FalseString;


or

C#
string bResume = bResume.ToString().ToLower()


will suffice
 
Share this answer
 
v2
Comments
nkhldhar 26-Jun-12 4:53am    
can u elaborate a bit
DamithSL 26-Jun-12 4:55am    
what is the bResume column type?
nkhldhar 26-Jun-12 4:57am    
bresume is a bool type variable its value is to be entered in a column namely resume which is of varchar type
[no name] 26-Jun-12 4:59am    
check your bresume column type in database. make sure its not bool if so then change the type to some other type which can accept string say string or varchar. now when you execute the code

string bResume = chkbResume.Checked ? bool.TrueString : bool.FalseString;

bResume will contain the text true/false based on your checkbox. now this will be inserted to database and will be stored as true/false.
But first of all make your question clear. do you want to print it or store it into database?
[no name] 26-Jun-12 5:00am    
now your column type is varchar, you dont need to worry just chnage the line

bool bResume = chkbResume.Checked;

to

string bResume = chkbResume.Checked ? bool.TrueString : bool.FalseString;
and execute
you only need to change one line

C#
command.Parameters.Add("@resume", bResume.ToString().ToLower());
 
Share this answer
 
v2

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