Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i have a code of checklistbox to textbox now i want to save textbox value in database,
C#
protected void Chkl1_SelectedIndexChanged(object sender, EventArgs e)
  {
      string code = "";
      for (int i = 0; i < Chkl1.Items.Count; i++)
      {
          if (Chkl1.Items[i].Selected)
          {
              Code += Chkl1.Items[i].Text + ",";
          }
      }
      TxtCodes.Text = Code;
  }


Now, i want to save all values of TxtCodes.Text in Database but i want save one by one delimeted values on Submit button clicked.

Please help me.

Thanks in Advance.

Ankit Agarwal.
Software Engineer
Posted
Updated 20-Aug-15 2:21am
v4
Comments
Patrice T 20-Aug-15 12:39pm    
How can you be a Software Engineer and ask such a basic question ?

1 solution

Don't.
Never store comma delimited data in a DB - it's a total PITA to work with.
Instead, use a second DB table which contains a foreign key to the original table row, and a single element of your data. You can then pick up the relevant data with a simple JOIN or WHERE clause.

Storing it as comma delimited seems easy, but causes massive headaches later when you try to do anything useful with the data.
 
Share this answer
 
Comments
Andy Lanng 20-Aug-15 8:17am    
Strongly agree - 5
Maciej Los 20-Aug-15 9:11am    
Strongly agree with strongly aggreement ;)
Shambhoo kumar 20-Aug-15 8:38am    
wah! what a nice explanation, i am agree with you. thanks for the kind of information +5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900