Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2008-11-05
4
Medium Priority
?
868 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:GravitaZ24
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:AmarIs26
ID: 22886634
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
 
LVL 6

Expert Comment

by:AmarIs26
ID: 22886651
oops meant you should be checking the Checked property of RadioButton
0
 

Author Comment

by:GravitaZ24
ID: 22887153
hrrrrrmm. that doesn't seem to be working
0
 

Accepted Solution

by:
GravitaZ24 earned 0 total points
ID: 22889370
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question