您的位置:首页 > 数据库

如何获得数据库表中某一字段中的以逗号分开的内容?

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

}

}

适用范围:仅能选择出字段中的一条记录,不能把该字段中的所有记录都选出来。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: