如何获得数据库表中某一字段中的以逗号分开的内容?
2012-11-26 12:32
483 查看
存储过程:
alter procedure sp_Tased
as
select FileUrl from tas where Sid=3
BLL层:unnions.cs
public string Unions_Sel()
{
List<unionsInfo> list = null;
unionsInfo info = null;
using (SqlDataReader reader = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "sp_Tased", null))
{
if (reader != null)
{
list = new List<unionsInfo>();
while (reader.Read())
{
info = new unionsInfo()
{
FileUrl = reader.GetString(0)
};
list.Add(info);
}
}
}
return info.FileUrl;
}
UI层:unionSelect.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="unionSelect.aspx.cs" Inherits="unionSelect" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="a" runat="server" Text="a"></asp:Label><br />
</div>
</form>
</body>
</html>
后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using BLL;
public partial class unionSelect : System.Web.UI.Page
{
private unions union = new unions();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BinGrid();
}
}
private void BinGrid()
{
string str = union.Unions_Sel();
string[] s = str.Split(',');
a.Text = s[2];
}
}
适用范围:仅能选择出字段中的一条记录,不能把该字段中的所有记录都选出来。
相关文章推荐
- 如何在数据库原有字段后增加内容?
- SQL server 2005 表中某一字段的所有值逗号分开的列表
- MyBatis从数据库取值的时候,当某一字段为null时,如何在返回前端的时候,也包含有这个字段
- mysql查询字段中以逗号分开内容
- SQL injection 1: 如何从数据库中获取想要获得的内容?
- 如何显示数据库long text 字段内容
- 如何获得数据库中的数据库名,表名,字段名,字段个数
- 如何获得Sybase中的数据库、表名、字段的SQL语句
- 水晶报表如何获得最新的数据库内容
- sql如何获得某个数据库里面的表的字段名,字段类型,字段长度(sql server)
- JAVA如何获得数据库的字段及字段类型
- 在数据库中将同一个字段的多个值用逗号分开,并且合并成一列的方法
- 【探讨】寻求去除数据库字段中存放重复内容的最佳方法
- 当写一个insert语句时,某一字段需要从需要插入的数据库中获取其最大值并且加1
- [转]SQLSERVER如何获取一个数据库中的所有表的名称、一个表中所有字段的名称
- JAVA中如何将以Date型的数据保存到数据库以Datetime型的字段中
- DBChart中获得X、Y坐标值和数据库相关字段值
- GridView性别列在数据库是bool型字段true or false,如何让其在页面中显示为男女?
- 查找 oracle 数据库中包含某一字段的表名
- SQL 将一个字段内用逗号分隔的内容分成多条记录