简体   繁体   English

如何使用vb.net将多个asp.net复选框值作为逗号分隔的字符串1,2,3,4,5插入到MSSQl数据库中?

[英]How to insert multiple asp.net checkboxes values to MSSQl database as comma seperaed string 1,2,3,4,5 using vb.net?

How to insert and retrive multiple asp.net checkboxes values to MSSQl database as comma seperaed string 1,2,3,4,5 using vb.net ? 如何使用vb.net将多个asp.net复选框值作为逗号分隔的字符串1,2,3,4,5插入并检索到MSSQl数据库?

and retrieve the inserted checkbox chekched in disabled form ..using vb.net 并使用vb.net检索以禁用形式..插入的复选框

example of this is : 例如:

http://www.redbus.in/Booking/SeatSelection.aspx?rt=4017230&doj=31-Dec-2010&dep=04:55%20PM&showSpInst=false http://www.redbus.in/Booking/SeatSelection.aspx?rt=4017230&doj=31-Dec-2010&dep=04:55%20PM&showSpInst=false

I want this type of whole layout in vb.net ... means if user registered selected seats then then next the same page load for todays date the selected seats will be disabled ... 我想在vb.net中使用这种整体布局...这意味着,如果用户注册了所选席位,那么在今天的下一个相同页面加载中,所选席位将被禁用...

pleas provide me the code snippet for that // insert and retrieve funda... in checkbox 请为我提供该代码段//在复选框中插入和检索基础...

Try with such a loop 尝试这样的循环

 string str = "";
            for (int i = 0; i <= 29; i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    string b = CheckBoxList1.Items[i].Value;
                    str += b + " , ";
                }

            }

than make an insert statement and you are putting all the checkbox values into a column. 而不是执行插入语句,而您会将所有复选框值放入一列中。 than just call select statement call the column 不仅仅是调用select语句调用列

You are doing a very bad thing storing lists of values in a single MSSQL column. 您正在做一个非常糟糕的事情,将值列表存储在单个MSSQL列中。 I know it may be convenient now, but it is always eventually bad news. 我知道现在可能很方便,但这始终永远是坏消息。 Why not store booked seats in their own table, one seat per row? 为什么不将预订的座位存储在自己的桌子上,每排一个座位? When you store a list of values in a column, you restrict access to the information stored in that column to only the code that can split the list. 当您将值列表存储在列中时,将访问该列中存储的信息的权限限制为只能拆分列表的代码。 It isn't available to database queries or to other code as a list, merely as a string. 数据库查询或其他代码不能以列表的形式使用它,而只能以字符串的形式使用。 You will end up replicating the code to split this string to other places that need the list data. 您将最终复制代码,以将该字符串拆分到其他需要列表数据的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM