ALTER PROCEDURE dbo.GetTitleTop
(
@kindid int,
@IntTop int
)
AS
declare @sql varchar(200)
set @sql='select top '+cast(@IntTop as varchar)+' * from guestbook where kindid='+cast(@kindid as varchar)
EXEC (@sql)
RETURN
前台代码:(
@kindid int,
@IntTop int
)
AS
declare @sql varchar(200)
set @sql='select top '+cast(@IntTop as varchar)+' * from guestbook where kindid='+cast(@kindid as varchar)
EXEC (@sql)
RETURN
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
KindId:<asp:TextBox ID="txtKindId" runat="server"></asp:TextBox>
<br />
条数: <asp:TextBox ID="txtIntTop" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="查看" OnClick="Button1_Click1" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="序号" />
<asp:BoundField DataField="kindId" HeaderText="类型编号" />
<asp:BoundField DataField="title" HeaderText="标题" />
<asp:BoundField DataField="body" HeaderText="内容" />
</Columns>
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>
后台代码:<!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>
KindId:<asp:TextBox ID="txtKindId" runat="server"></asp:TextBox>
<br />
条数: <asp:TextBox ID="txtIntTop" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="查看" OnClick="Button1_Click1" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="id" HeaderText="序号" />
<asp:BoundField DataField="kindId" HeaderText="类型编号" />
<asp:BoundField DataField="title" HeaderText="标题" />
<asp:BoundField DataField="body" HeaderText="内容" />
</Columns>
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
string connstr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection con = new SqlConnection(connstr);
if (con.State.Equals(ConnectionState.Closed))
{
con.Open();
}
string procName = "dbo.GetTitleTop";
SqlCommand cmd = new SqlCommand(procName, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@kindid", SqlDbType.Int);
cmd.Parameters.Add("@IntTop", SqlDbType.Int);
cmd.Parameters[0].Value = Convert.ToInt32(this.txtKindId.Text.Trim());
cmd.Parameters[1].Value = Convert.ToInt32(this.txtIntTop.Text.Trim());
SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
this.GridView1.DataSource = sdr;
this.GridView1.DataBind();
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
string connstr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection con = new SqlConnection(connstr);
if (con.State.Equals(ConnectionState.Closed))
{
con.Open();
}
string procName = "dbo.GetTitleTop";
SqlCommand cmd = new SqlCommand(procName, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@kindid", SqlDbType.Int);
cmd.Parameters.Add("@IntTop", SqlDbType.Int);
cmd.Parameters[0].Value = Convert.ToInt32(this.txtKindId.Text.Trim());
cmd.Parameters[1].Value = Convert.ToInt32(this.txtIntTop.Text.Trim());
SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
this.GridView1.DataSource = sdr;
this.GridView1.DataBind();
}
}