Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi !!!
in my program i need to store radio button's value in database so i used bit datatype for storing value and write bellow code
#region Insert
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            else
                con.Close();
            if (button2.Text == "Add")
            {
                CustomUnLock();
                textBox1.ReadOnly = false;
                button2.Text = "Save";
            }
            else
            {
                if (radioButton1.Checked == true)
                {
                    cmd = new SqlCommand("PPrimaryInsert", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@grnum", textBox1.Text));
                    cmd.Parameters.Add(new SqlParameter("@std", int.Parse(txtstd.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PStname", textBoxAlphabetic1.Text));
                    cmd.Parameters.Add(new SqlParameter("@PRollno", int.Parse(txtrolnum.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PConcesion", radioButton1.Text));
                    cmd.Parameters.Add(new SqlParameter("@PAdmissionfee", int.Parse(txtadmission.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PSchoolfee", int.Parse(txtschool.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PTermfee", int.Parse(txtterm.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PMisalliancefee", int.Parse(txtmisalliance.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PUniformfee", int.Parse(txtuniform.Text)));
                    if (radioButton3.Checked == true)
                        cmd.Parameters.Add(new SqlParameter("@Pbus", radioButton3.Text));
                    else
                        cmd.Parameters.Add(new SqlParameter("@Pnonbus", radioButton4.Text));
 
                    cmd.Parameters.Add(new SqlParameter("@PSchoobusfee", int.Parse(txtbus.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlAdmissionfee", int.Parse(txtadmissionamt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlSchoolfee", int.Parse(txtschoolamnt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlTermfee", int.Parse(txttermamnt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlMisalliancefee", int.Parse(txtmisallianceamnt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlSchoobusfee", int.Parse(txtbusamnt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlUniformfee", int.Parse(txtuniformamnt.Text)));
 
                    int i = cmd.ExecuteNonQuery();
                    label16.Text = i + "Record Added Successfully...";
                    CustomClear();
                }
                else
                {
 
                    cmd = new SqlCommand("PPrimaryInsert", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@grnum", textBox1.Text));
                    cmd.Parameters.Add(new SqlParameter("@std", int.Parse(txtstd.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PStname", textBoxAlphabetic1.Text));
                    cmd.Parameters.Add(new SqlParameter("@PRollno", int.Parse(txtrolnum.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PNonconcesion", radioButton2.Text));
                    cmd.Parameters.Add(new SqlParameter("@PAdmissionfee", int.Parse(txtadmission.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PSchoolfee", int.Parse(txtschool.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PTermfee", int.Parse(txtterm.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PMisalliancefee", int.Parse(txtmisalliance.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PUniformfee", int.Parse(txtuniform.Text)));
                    if (radioButton3.Checked == true)
                        cmd.Parameters.Add(new SqlParameter("@Pbus", radioButton3.Text));
                    else
                        cmd.Parameters.Add(new SqlParameter("@Pnonbus", radioButton4.Text));
 
                    cmd.Parameters.Add(new SqlParameter("@PSchoobusfee", int.Parse(txtbus.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlAdmissionfee", int.Parse(txtadmissionamt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlSchoolfee", int.Parse(txtschoolamnt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlTermfee", int.Parse(txttermamnt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlMisalliancefee", int.Parse(txtmisallianceamnt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlSchoobusfee", int.Parse(txtbusamnt.Text)));
                    cmd.Parameters.Add(new SqlParameter("@PActlUniformfee", int.Parse(txtuniformamnt.Text)));
 
                    int i = cmd.ExecuteNonQuery();
                    label16.Text = i + "Record Added Successfully...";
                    CustomClear();
                }
 
            }
 
#endregion
but while clicking on save button cmd.Executenonquery() shows error
Please help..
Posted 14-Apr-13 7:10am
Arifa S508
Edited 14-Apr-13 7:38am
v2
Comments
Member 9823122 at 14-Apr-13 12:22pm
   
The Error is "Error converting data type nvarchar to bit."
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The Error is "Error converting data type nvarchar to bit."
Based on the error, it seems you are passing a value to database that should be a boolean data and not a string.
 
Make sure you have assigned correct values to all the parameters as per expected by column type. You query formed should pass the right data.
  Permalink  
Comments
Member 9823122 at 15-Apr-13 3:59am
   
SO SIR what will be the datatype??? i used bit
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hello to all!!
i got my point...Smile | :)
whenever we want to store a text of radio button that time use nvarchar datatype in database..
my mistake was i took bit as datatype of radiobutton as we know bit can store either 0 or 1 but i was storing text of radio button thats why error was thrown "Error converting data type nvarchar to bit."
 
Thanks for reading..
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 436
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 170
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 15 Apr 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