如何从db中检索具有相同列值的多个记录并显示在Web表单的标签中? [英] How can I retrieve multiple record having one column value same from db and display in label of web form?

查看:73
本文介绍了如何从db中检索具有相同列值的多个记录并显示在Web表单的标签中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带有Value的表列名称如下:

Log_ID是外键而不是主键

Log_ID ..... Start_Date ..... End_Date .. ... Deposit_Sum ..... Payment_Frequency

7 ............. 2014-11-12 .... 2015-11-12 .... ...... 2131 ...........................每年

8 ...... ...... 2014-11-12 ...... 2016-11-12 ............ 10000 ............... .........每年

7 ............. 2014-11-12 ...... 2019-11-12 .. ......... 50000 ....... .......................每年

9 ............. 2014-12-12 ...... 2019年12月12日........... 100000 ......... .. ............每半年



我只能为Log_ID = 7取回单行

但是

如何检索已经得到id = 7的行记录?

解决方案

我不知道是什么控制你正在使用?但是,基于我的观察,如果你使用sql server作为数据库,那么你的查询可能是这样的,

  select  Log_ID,Start_Date,End_Date,Deposit_Sum,Payment_Frequency 来自 YourTableName 其中 Log_ID =  7  



只需将此绑定到您的控件上。希望它对您有所帮助。


  DECLARE   @cols   NVARCHAR (MAX)

SELECT @cols = STUFF(( SELECT DISTINCT + ' ,' + MyData FROM
SELECT + ' 开始:' + 转换 Nvarchar ,[StartDate], 121 )+ ' 结束:' + 转换 Nvarchar ,[EndDate], 121
+ ' 存款:' + cast([Deposit_Sum] as Nvarchar )+ ' 模式:' + [Payment_Frequency] as [MyData]
FROM [TestDB]。[dbo]。[TblTempLog] 其中 log_id = 7
)a
ORDER BY ' ,' + MyData
FOR XML PATH( ' '
), 1 2 ' ') + ' '

选择 @cols



结果为您提供逗号分隔所有值在一列中。


Table column name with Value is as below:
Log_ID is foreign key not primary key
Log_ID .....Start_Date .....End_Date .....Deposit_Sum .....Payment_Frequency
7.............2014-11-12 ....2015-11-12 ..........2131 ...........................Yearly
8............2014-11-12......2016-11-12............10000 ........................Yearly
7.............2014-11-12......2019-11-12...........50000....... .......................Yearly
9.............2014-12-12......2019-12-12...........100000 ........... ............Half Yearly

I am only able to retrieve single row for Log_ID = 7
But
How can I retrieve both row record which has got id= 7?

解决方案

I don't know what control you are using? but,based on my observation if you use sql server as database,then your query may be like this,

select Log_ID,Start_Date,End_Date,Deposit_Sum,Payment_Frequency from YourTableName where Log_ID=7


Just bind this to your control.Hope it may helpful for you.


DECLARE @cols NVARCHAR(MAX)

SELECT  @cols = STUFF(( SELECT DISTINCT + ',' + MyData FROM    (
SELECT  +'Start: ' + Convert(Nvarchar,[StartDate],121) + ' End: ' +  Convert(Nvarchar,[EndDate],121)
+' Deposit: ' + cast([Deposit_Sum] as Nvarchar) + ' Mode: ' + [Payment_Frequency] as [MyData]
FROM [TestDB].[dbo].[TblTempLog] where log_id = 7
)a 
ORDER BY ',' + MyData
FOR XML PATH('')
), 1, 2, '') + ''

select  @cols


The Result gives you comma separated all valued in one column.


这篇关于如何从db中检索具有相同列值的多个记录并显示在Web表单的标签中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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