Update radiobutton boolean values to tha database with C# on codebehind page

Hi, I have a few radio buttons on my aspx page.How would I go about storing the Boolean (bit) values into the database using the code behind and c#, checked for true and unchecked for false of course.

Everything else is working except for the radiobuttons, I'm not sure how to go about this, I tried below

protected void InsertButton_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=Prop_Change;Integrated Security=SSPI");
        SqlCommand com = new SqlCommand("Insert into PropChanges_AQMain(Co_Name, Office, Sub_Date, Proj_Name, State, County, Tax_Dist,Inf_Other, Rec_Date, Rec_VolBook,Rec_Page,Rec_InstNo,Rec_AgNo,Rec_AdAgNo,ASFS_FRACT_N,ASFS_FRACT_D,ASFS_GROSSAC,ASFS_NETAC,ASFS_OVERLAP,ASFS_TAXPARCELID,ASSurf_FRACT_N,ASSurf_FRACT_D,ASSurf_GROSSAC,ASSurf_NETAC,ASSurf_OVERLAP,ASSurf_TAXPARCELID,ASCoal_FRACT_N,ASCoal_FRACT_D,ASCoal_GROSSAC,ASCoal_NETAC,ASCoal_OVERLAP,ASCoal_TAXPARCELID,ASOG_FRACT_N,ASOG_FRACT_D,ASOG_GROSSAC,ASOG_NETAC,ASOG_OVERLAP,ASOG_TAXPARCELID,ASMR_FRACT_N,ASMR_FRACT_D,ASMR_GROSSAC,ASMR_NETAC,ASMR_OVERLAP,ASMR_TAXPARCELID,ASCM_FRACT_N,ASCM_FRACT_D,ASCM_GROSSAC,ASCM_NETAC,ASCM_OVERLAP,ASCM_TAXPARCELID,ASOther_FRACT_N,ASOther_FRACT_D,ASOther_GROSSAC,ASOther_NETAC,ASOther_OVERLAP,ASOther_TAXPARCELID,AdInformation,EN_OrigDocumentIMG,EN_OrigDocumentIMG_DESC,EN_ClosingSettIMG,EN_ClosingSettIMG_DESC,EN_RecordedMemIMG,EN_RecordedMemIMG_DESC,EN_OccRentIMG,EN_OccRentIMG_DESC,EN_AcqDispApprIMG,EN_AcqDispApprIMG_DESC,EN_DiscStateIMG,EN_DiscStateIMG_DESC,EN_NonForeignAffIMG,EN_NonForeignAffIMG_DESC,EN_OwnersAffIMG,EN_OwnersAffIMG_DESC,EN_1009SIMG,EN_1009SIMG_DESC,EN_PaintDiscIMG,EN_PaintDiscIMG_DESC,EN_TitleOpinIMG,EN_TitleOpinIMG_DESC,EN_PhotosIMG,EN_PhotosIMG_DESC,EN_ApprIMG,EN_ApprIMG_DESC,EN_MapIMG,EN_MapIMG_DESC,EN_AdditionalIMG,EN_AdditionalIMG_DESC,EN_DocFowLaterIMG,EN_DocFowLaterIMG_DESC,Prep_By) values(@Co_Name, @Office, @Sub_Date, @Proj_Name,@State,@County,@Tax_Dist,@Inf_Other, @Rec_Date, @Rec_VolBook,@Rec_Page,@Rec_InstNo,@Rec_AgNo,@Rec_AdAgNo,@ASFS_FRACT_N,@ASFS_FRACT_D,@ASFS_GROSSAC,@ASFS_NETAC,@ASFS_OVERLAP,@ASFS_TAXPARCELID,@ASSurf_FRACT_N,@ASSurf_FRACT_D,@ASSurf_GROSSAC,@ASSurf_NETAC,@ASSurf_OVERLAP,@ASSurf_TAXPARCELID,@ASCoal_FRACT_N,@ASCoal_FRACT_D,@ASCoal_GROSSAC,@ASCoal_NETAC,@ASCoal_OVERLAP,@ASCoal_TAXPARCELID,@ASOG_FRACT_N,@ASOG_FRACT_D,@ASOG_GROSSAC,@ASOG_NETAC,@ASOG_OVERLAP,@ASOG_TAXPARCELID,@ASMR_FRACT_N,@ASMR_FRACT_D,@ASMR_GROSSAC,@ASMR_NETAC,@ASMR_OVERLAP,@ASMR_TAXPARCELID,@ASCM_FRACT_N,@ASCM_FRACT_D,@ASCM_GROSSAC,@ASCM_NETAC,@ASCM_OVERLAP,@ASCM_TAXPARCELID,@ASOther_FRACT_N,@ASOther_FRACT_D,@ASOther_GROSSAC,@ASOther_NETAC,@ASOther_OVERLAP,@ASOther_TAXPARCELID,@AdInformation,@EN_OrigDocumentIMG,@EN_OrigDocumentIMG_DESC,@EN_ClosingSettIMG,@EN_ClosingSettIMG_DESC,@EN_RecordedMemIMG,@EN_RecordedMemIMG_DESC,@EN_OccRentIMG,@EN_OccRentIMG_DESC,@EN_AcqDispApprIMG,@EN_AcqDispApprIMG_DESC,@EN_DiscStateIMG,@EN_DiscStateIMG_DESC,@EN_NonForeignAffIMG,@EN_NonForeignAffIMG_DESC,@EN_OwnersAffIMG,@EN_OwnersAffIMG_DESC,@EN_1009SIMG,@EN_1009SIMG_DESC,@EN_PaintDiscIMG,@EN_PaintDiscIMG_DESC,@EN_TitleOpinIMG,@EN_TitleOpinIMG_DESC,@EN_PhotosIMG,@EN_PhotosIMG_DESC,@EN_ApprIMG,@EN_ApprIMG_DESC,@EN_MapIMG,@EN_MapIMG_DESC,@EN_AdditionalIMG,@EN_AdditionalIMG_DESC,@EN_DocFowLaterIMG,@EN_DocFowLaterIMG_DESC,@Prep_By)", con);
        string strPath = string.Empty;
        int intResult = 0;
        con.Open();
 
 RadioButton TCIProratedRB = (RadioButton)FormView1.FindControl("TCI_ProratedYNRB");
        string rbutton1 = TCIProratedRB.bit.Trim();
        com.Parameters.Add("TCI_ProratedYNRB", SqlDbType.bit, 1, "TCI_ProratedYNRB").Value = Server.HtmlEncode(rbutton1);
        
try
        {
            intResult = Convert.ToInt32(com.ExecuteNonQuery());
 
            if (intResult != 0)
            {
                if (file1.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file1.PostedFile.FileName));
                    file1.SaveAs(strPath);
                }
 
                if (file2.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file2.PostedFile.FileName));
                    file2.SaveAs(strPath);
                }
                
                
                if (file3.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file3.PostedFile.FileName));
                    file3.SaveAs(strPath);
                }
                
                if (file4.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file4.PostedFile.FileName));
                    file4.SaveAs(strPath);
                }
 
                if (file5.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file5.PostedFile.FileName));
                    file5.SaveAs(strPath);
                }
 
                if (file6.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file6.PostedFile.FileName));
                    file6.SaveAs(strPath);
                }
 
                if (file7.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file7.PostedFile.FileName));
                    file7.SaveAs(strPath);
                }
 
                if (file8.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file8.PostedFile.FileName));
                    file8.SaveAs(strPath);
                }
 
                if (file9.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file9.PostedFile.FileName));
                    file9.SaveAs(strPath);
                }
 
                if (file10.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file10.PostedFile.FileName));
                    file10.SaveAs(strPath);
                }
 
                if (file11.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file11.PostedFile.FileName));
                    file11.SaveAs(strPath);
                }
 
                if (file12.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file12.PostedFile.FileName));
                    file12.SaveAs(strPath);
                }
 
                if (file13.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file13.PostedFile.FileName));
                    file13.SaveAs(strPath);
                }
 
                if (file14.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file14.PostedFile.FileName));
                    file14.SaveAs(strPath);
                }
 
                if (file15.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file15.PostedFile.FileName));
                    file15.SaveAs(strPath);
                }
 
                if (file16.HasFile)
                {
                    strPath = (Server.MapPath("images/") + Path.GetFileName(file16.PostedFile.FileName));
                    file16.SaveAs(strPath);
                }
 
                Response.Write("Records Entered and Images Uploaded.");
            }
            else
            {
                Response.Write("No images uploaded.");
            }
        }
        catch
        {
            Response.Write("Failed to upload images.  There was a database error.");
        }
    }
}

Open in new window

GravitaZ24Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AmarIs26Commented:
Dont know much about formview but surly you should be accessing the Checked property of the dropdown.
so the code should be
 RadioButton TCIProratedRB = (RadioButton)FormView1.FindControl("TCI_ProratedYNRB");
       
        com.Parameters.Add("TCI_ProratedYNRB", SqlDbType.bit, 1, "TCI_ProratedYNRB").Value = TCIProratedRB.Checked;

 
0
AmarIs26Commented:
oops meant you should be checking the Checked property of RadioButton
0
GravitaZ24Author Commented:
hrrrrrmm. that doesn't seem to be working
0
GravitaZ24Author Commented:
I figured it out this way, thanks for the help though

RadioButton TCIProratedRB = (RadioButton)FormView1.FindControl("TCI_ProratedYNRB");
        int flag;
 
        if (TCIProratedRB.Checked)
        {
        flag = 1;
        }
         else
        {
       flag = 0;
        }
        com.Parameters.Add("@TCI_ProratedYN", SqlDbType.Bit, 1, "TCI_ProratedYN").Value = flag;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.