存储过程:
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];
}
}
适用范围:仅能选择出字段中的一条记录,不能把该字段中的所有记录都选出来。