We help IT Professionals succeed at work.
Get Started

Insert CheckBox Checked data into database

767 Views
Last Modified: 2012-08-13
Hello!

I have a form where I am colledting data. I have a few checkbox controls that I need to insert into the database "true" if is checked or "false" if it is not. Here is the OnClick code for inserting the data into my database. I have placed ????? where the checkbaoxes are located.

Thanks for your help!!

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string values = "";
       
        foreach (ListItem li in CategoryList.Items)
        {
            if (li.Selected)
            {
               values += li.Text + ", ";
            }
            }  
               SqlDataSource SqlDataSource1 = new SqlDataSource();
               SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["website_ConnectionString"].ToString();

               SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
               SqlDataSource1.InsertCommand = "INSERT INTO Suppliers (SupplierName, CoDescription, ParentCorporation, Address, Address2, City, StateOrProvince, PostalCode, Country, ContactName, PhoneNumber, FaxNumber, EmailAddress, website, QAP_ASMENQA_1, QAP_10CFR21, QAP_10CFR50, QAP_Other, NUPIC_Audit, NUPIC_Date, Certs, NRC_Licenses, Brands, Categories, Cat_Notes) VALUES (@SupplierName, @CoDescription, @ParentCorporation, @Address, @Address2, @City, @StateOrProvince, @PostalCode, @Country, @ContactName, @PhoneNumber, @FaxNumber, @EmailAddress, @website, @QAP_ASMENQA_1, @QAP_10CFR21, @QAP_10CFR50, @QAP_Other, @NUPIC_Audit, @NUPIC_Date, @Certs, @NRC_Licenses, @Brands, @CategoryList, @Cat_Notes)";
               SqlDataSource1.InsertParameters.Add("SupplierName", SupplierName.Text);
               SqlDataSource1.InsertParameters.Add("CoDescription", CoDescriptionEditor.Text);
               SqlDataSource1.InsertParameters.Add("ParentCorporation", ParentCorporationTextBox.Text);
               SqlDataSource1.InsertParameters.Add("Address", AddressTextBox.Text);
               SqlDataSource1.InsertParameters.Add("Address2", AddressTextBox2.Text);
               SqlDataSource1.InsertParameters.Add("City", CityTextBox.Text);
               SqlDataSource1.InsertParameters.Add("StateOrProvince", StateOrProvinceTextBox.Text);
               SqlDataSource1.InsertParameters.Add("PostalCode", PostalCodeTextBox.Text);
               SqlDataSource1.InsertParameters.Add("Country", CountryTextBox.Text);
               SqlDataSource1.InsertParameters.Add("ContactName", ContactNameTextBox.Text);
               SqlDataSource1.InsertParameters.Add("PhoneNumber", PhoneNumberTextBox.Text);
               SqlDataSource1.InsertParameters.Add("FaxNumber", FaxNumberTextBox.Text);
               SqlDataSource1.InsertParameters.Add("EmailAddress", EmailAddressTextBox.Text);
               SqlDataSource1.InsertParameters.Add("website", WebsiteTextBox.Text);
               SqlDataSource1.InsertParameters.Add("QAP_ASMENQA_1", NQA1CheckBox.???????);
               SqlDataSource1.InsertParameters.Add("QAP_10CFR21", CFR21CheckBox.???????);
               SqlDataSource1.InsertParameters.Add("QAP_10CFR50", CFR50CheckBox.???????);
               SqlDataSource1.InsertParameters.Add("QAP_Other", QAPotherTextBox.Text);
               SqlDataSource1.InsertParameters.Add("NUPIC_Audit", NUPICCheckBox.???????);
               SqlDataSource1.InsertParameters.Add("NUPIC_Date", NUPICDateTextBox.Text);
               SqlDataSource1.InsertParameters.Add("Certs", CertsTextBox.Text);
               SqlDataSource1.InsertParameters.Add("NRC_Licenses", NRCTextBox.Text);
               SqlDataSource1.InsertParameters.Add("Brands", BrandsTextBox.Text);
               SqlDataSource1.InsertParameters.Add("CategoryList", values);
               SqlDataSource1.InsertParameters.Add("Cat_Notes", NotesTextBox.Text);

               values = values.TrimEnd(',');

               SqlDataSource1.Insert();

               SqlDataSource1 = null;

            }
                       
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE