存储过程代码如下:
-----------------------------------------------------------------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER PROCEDURE [dbo].[ReadIntro]
@pbody varchar(50),
@pclicks varchar(50),
@pwriter varchar(50),
@ptime varchar(50)
AS
BEGIN SET NOCOUNT ON; SELECT @pbody as cont,bodyclix as clicks,@ptime as updatetime,@pwriter as writer from intro
END
------------------------------------------------------------------------------------------------------
cs文件如下:
------------------------------------------------------------------------------------------------------
String strconstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection connection_intro = new SqlConnection(strconstring); SqlCommand command_intro = new SqlCommand();
command_intro.Connection = connection_intro;
command_intro.CommandText = "Readintro";
command_intro.Parameters.Add(new SqlParameter("@pbody ", SqlDbType.VarChar,50));
command_intro.Parameters["@pbody "].Value = "body";
command_intro.Parameters.Add(new SqlParameter("@pclicks ", SqlDbType.VarChar, 50));
command_intro.Parameters["@pclicks "].Value = "bodyclix";
command_intro.Parameters.Add(new SqlParameter("@ptime ", SqlDbType.VarChar, 50));
command_intro.Parameters["@ptime "].Value = "bodytime";
command_intro.Parameters.Add(new SqlParameter("@pwriter ", SqlDbType.VarChar, 50));
command_intro.Parameters["@pwriter "].Value = "bodywriter";
command_intro.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapter_intro = new SqlDataAdapter(command_intro);
DataTable data_intro = new DataTable();
adapter_intro.Fill(data_intro); DataList1.DataSource = data_intro;
DataList1.DataBind();
--------------------------------------------------------------------------------------------------------
aspx文件如下:
--------------------------------------------------------------------------------------------------------
<asp:DataList ID="DataList1" runat="server" ShowFooter="False" CellPadding="0" CellSpacing="0" ShowHeader="False" Width="100%">
<ItemTemplate>
<div class="author">点击数:<span><asp:Label id="Label1" runat="server" Text='<%# Eval("clicks") %>' ></asp:Label></span>次
作者:<span><asp:Label id="Label2" runat="server" Text='<%# Eval("writer") %>' ></asp:Label></span>
添加时间:<span><asp:Label id="Label3" runat="server" Text='<%# Eval("updatetime") %>' ></asp:Label></span>
</div>
<div class="con_text">
<div class="c_content_text">
<div class="c_content_overflow" id="fontzoom">
<p style="line-height: 18pt; text-indent: 21pt; background: white;"><asp:Label id="Label4" runat="server" Text='<%# Eval("cont") %>' ></asp:Label>
<br/>
<br/>
</div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
------------------------------------------------------------------------------------------------------------
我希望实现的是:给存储过程输入参数作为字段名,然后用datalist绑定查询出来的结果,可是结果显示的是我输入参数的值,即body,bodyclix,bodywrier,bodytime,没显示具体的查询结构。请各位帮忙,十分感谢!
非常着急。
-----------------------------------------------------------------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER PROCEDURE [dbo].[ReadIntro]
@pbody varchar(50),
@pclicks varchar(50),
@pwriter varchar(50),
@ptime varchar(50)
AS
BEGIN SET NOCOUNT ON; SELECT @pbody as cont,bodyclix as clicks,@ptime as updatetime,@pwriter as writer from intro
END
------------------------------------------------------------------------------------------------------
cs文件如下:
------------------------------------------------------------------------------------------------------
String strconstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection connection_intro = new SqlConnection(strconstring); SqlCommand command_intro = new SqlCommand();
command_intro.Connection = connection_intro;
command_intro.CommandText = "Readintro";
command_intro.Parameters.Add(new SqlParameter("@pbody ", SqlDbType.VarChar,50));
command_intro.Parameters["@pbody "].Value = "body";
command_intro.Parameters.Add(new SqlParameter("@pclicks ", SqlDbType.VarChar, 50));
command_intro.Parameters["@pclicks "].Value = "bodyclix";
command_intro.Parameters.Add(new SqlParameter("@ptime ", SqlDbType.VarChar, 50));
command_intro.Parameters["@ptime "].Value = "bodytime";
command_intro.Parameters.Add(new SqlParameter("@pwriter ", SqlDbType.VarChar, 50));
command_intro.Parameters["@pwriter "].Value = "bodywriter";
command_intro.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapter_intro = new SqlDataAdapter(command_intro);
DataTable data_intro = new DataTable();
adapter_intro.Fill(data_intro); DataList1.DataSource = data_intro;
DataList1.DataBind();
--------------------------------------------------------------------------------------------------------
aspx文件如下:
--------------------------------------------------------------------------------------------------------
<asp:DataList ID="DataList1" runat="server" ShowFooter="False" CellPadding="0" CellSpacing="0" ShowHeader="False" Width="100%">
<ItemTemplate>
<div class="author">点击数:<span><asp:Label id="Label1" runat="server" Text='<%# Eval("clicks") %>' ></asp:Label></span>次
作者:<span><asp:Label id="Label2" runat="server" Text='<%# Eval("writer") %>' ></asp:Label></span>
添加时间:<span><asp:Label id="Label3" runat="server" Text='<%# Eval("updatetime") %>' ></asp:Label></span>
</div>
<div class="con_text">
<div class="c_content_text">
<div class="c_content_overflow" id="fontzoom">
<p style="line-height: 18pt; text-indent: 21pt; background: white;"><asp:Label id="Label4" runat="server" Text='<%# Eval("cont") %>' ></asp:Label>
<br/>
<br/>
</div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
------------------------------------------------------------------------------------------------------------
我希望实现的是:给存储过程输入参数作为字段名,然后用datalist绑定查询出来的结果,可是结果显示的是我输入参数的值,即body,bodyclix,bodywrier,bodytime,没显示具体的查询结构。请各位帮忙,十分感谢!
非常着急。
SELECT 'bodyclix' as cont,'bodyclix'as clicks,' bodytime' as updatetime,'bodywrier' as writer from intro你执行的效果相当于这样..