如何使用c#asp.net在数据库中保存多个逗号分隔的文本框值? [英] How to save multiple coma separated values of textbox in database using c# asp.net?

查看:70
本文介绍了如何使用c#asp.net在数据库中保存多个逗号分隔的文本框值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



i有一个checklistbox代码到文本框现在我想保存数据库中的文本框值,

Hello,

i have a code of checklistbox to textbox now i want to save textbox value in database,

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;
  }





现在,我想在数据库中保存TxtCodes.Text的所有值,但我希望逐个保存单击提交按钮上的值。



请帮帮我。



先谢谢。



Ankit Agarwal。

软件工程师



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

推荐答案

不要。

永远不要在数据库中存储逗号分隔的数据 - 这是一个可以使用的总PITA。

相反,使用第二个DB表,其中包含原始表行的外键,以及单个表您的数据元素。然后,您可以使用简单的JOIN或WHERE子句获取相关数据。



将其存储为逗号分隔似乎很容易,但是当您尝试执行此操作时会导致严重的麻烦对数据有用的任何内容。
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.


这篇关于如何使用c#asp.net在数据库中保存多个逗号分隔的文本框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆