Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 从数据库检索复选框列表选择_Asp.net_Sql Server_Checkboxlist - Fatal编程技术网

Asp.net 从数据库检索复选框列表选择

Asp.net 从数据库检索复选框列表选择,asp.net,sql-server,checkboxlist,Asp.net,Sql Server,Checkboxlist,我有一个复选框列表,当提交时,它将选择存储在一个带有userid的表中。该表如下所示: Create table tblInterestByUserId ( Id int primary key identity, UserId varchar(10), SubInterestId int, SubInterest varchar(20), InterestId int ) 现在,我想根据SubInterestId

我有一个复选框列表,当提交时,它将选择存储在一个带有userid的表中。该表如下所示:

    Create table tblInterestByUserId
     (
     Id int primary key identity,
     UserId varchar(10),
     SubInterestId int,
     SubInterest varchar(20),
     InterestId int
      )
现在,我想根据SubInterestId在另一页上的另一个复选框列表中检索所选内容。我想在新页上执行以下操作:

1.检查所选用户标识的tblInterestByUserId中插入的所有子兴趣行。 2.根据tblInterestByUserId中已存在的子兴趣填充该用户ID的复选框列表


请帮我在加载页面上输入相同的代码

也许是一个获取所需数据的过程

CREATE PROCEDURE get_selections 
 @SubInterestId INT 
AS
BEGIN
  SET NOCOUNT ON;

   SELECT SubInterest FROM tblInterestByUserId
   WHERE SubInterestId = @SubInterestId
END

从应用程序代码调用此过程我的建议是使用一个带有标记的枚举,该标记在C中与subinterestID映射,这样您就可以选择存储的ID并将其分配给枚举。 见此:

可能使用select语句?我知道我必须使用select语句。我对使用Read循环或其他东西感到困惑?我需要一个开始。你为什么把次级利息varchar20放在这张桌子上?它应该在不同的表中,并且在此表中只有它的idIt用于不同的目的。不能有任何其他表。忽略其他列。唯一需要关注的是UserId和SubInterestId是的,您可以在后面使用Read loopCode吗?我的意思是,这就是我完全空白的地方。我也可以用一个简单的select语句来完成。所以你的问题不在于SQL,而在于ASP.Net。请更好地描述您的问题,这样人们就不必花时间回答错误的问题。枚举对于动态数据来说是一个糟糕的选择。除非您认为更改系统中添加或删除的每个子兴趣的代码是一个好主意,否则您是对的,这种方法主要用于静态复选框列表