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.ConnectionS tring = ConfigurationManager.Conne ctionStrin gs["websit e_Connecti onString"] .ToString( );
SqlDataSource1.InsertComma ndType = SqlDataSourceCommandType.T ext;
SqlDataSource1.InsertComma nd = "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.InsertParam eters.Add( "SupplierN ame", SupplierName.Text);
SqlDataSource1.InsertParam eters.Add( "CoDescrip tion", CoDescriptionEditor.Text);
SqlDataSource1.InsertParam eters.Add( "ParentCor poration", ParentCorporationTextBox.T ext);
SqlDataSource1.InsertParam eters.Add( "Address", AddressTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "Address2" , AddressTextBox2.Text);
SqlDataSource1.InsertParam eters.Add( "City", CityTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "StateOrPr ovince", StateOrProvinceTextBox.Tex t);
SqlDataSource1.InsertParam eters.Add( "PostalCod e", PostalCodeTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "Country", CountryTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "ContactNa me", ContactNameTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "PhoneNumb er", PhoneNumberTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "FaxNumber ", FaxNumberTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "EmailAddr ess", EmailAddressTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "website", WebsiteTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "QAP_ASMEN QA_1", NQA1CheckBox.???????);
SqlDataSource1.InsertParam eters.Add( "QAP_10CFR 21", CFR21CheckBox.???????);
SqlDataSource1.InsertParam eters.Add( "QAP_10CFR 50", CFR50CheckBox.???????);
SqlDataSource1.InsertParam eters.Add( "QAP_Other ", QAPotherTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "NUPIC_Aud it", NUPICCheckBox.???????);
SqlDataSource1.InsertParam eters.Add( "NUPIC_Dat e", NUPICDateTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "Certs", CertsTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "NRC_Licen ses", NRCTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "Brands", BrandsTextBox.Text);
SqlDataSource1.InsertParam eters.Add( "CategoryL ist", values);
SqlDataSource1.InsertParam eters.Add( "Cat_Notes ", NotesTextBox.Text);
values = values.TrimEnd(',');
SqlDataSource1.Insert();
SqlDataSource1 = null;
}
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.ConnectionS
SqlDataSource1.InsertComma
SqlDataSource1.InsertComma
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
SqlDataSource1.InsertParam
values = values.TrimEnd(',');
SqlDataSource1.Insert();
SqlDataSource1 = null;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dkloeck, Your example worked great! Thanks for your help!!!
ASKER
Thanks for your help araim but dkloeck's solution worked. Thanks for posting.
but you can get the checkbox state like this:
NQA1CheckBox.Checked