Link to home
Start Free TrialLog in
Avatar of Cyberzones
Cyberzones

asked on

Insert CheckBox Checked data into database

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;

            }
                       
ASKER CERTIFIED SOLUTION
Avatar of dkloeck
dkloeck
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't know what type is QAP_ASMENQA_1
but you can get the checkbox state like this:

NQA1CheckBox.Checked
Avatar of Cyberzones
Cyberzones

ASKER

dkloeck, Your example worked great! Thanks for your help!!!
Thanks for your help araim but dkloeck's solution worked. Thanks for posting.