存储过程怎么写?
请给一个例子.网上很多看不明白.
就给一个不带参的例子就行了.
SqlConnection con = new SqlConnection( "server=.;database=2006;uid=sa;pwd=; ");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand();
sda.SelectCommand.Connection = con;
sda.SelectCommand.CommandText = "Protest ";
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
sda.Fill(ds);
this.repTest.DataSource = ds.Tables[0].DefaultView;
this.repTest.DataBind();
我就是想查询表A的所有记录,然后绑定到repeater.
那么Protest怎么写??是在数据库中写吗???
------解决方案--------------------CREATE PROCEDURE Protest
AS
SELECT * FROM 表A
------解决方案--------------------参考一下SQL Server相关文档!
------解决方案--------------------CREATE PROCEDURE datav
as
SELECT iyear, iperiod, SUBSTRING(ccode, 1, 4) AS ccodenew, cdept_id, SUM(md)
AS smd, SUM(mc) AS smc, SUM(nd_s) AS snd, SUM(nc_s) AS snc
FROM dbo.GL_accvouch_qry
GROUP BY iyear, iperiod, SUBSTRING(ccode, 1, 4), cdept_id
GO
------解决方案--------------------给你个经典的
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE pagination3
@tblName varchar(200), -- 表名
@strGetFields varchar(1000) = '* ', -- 需要返回的列
@fldName varchar(255)= ' ' ' ', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1500) = ' ' ' ' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL varchar(5000) -- 主语句
declare @strTmp varchar(110) -- 临时变量
declare @strOrder varchar(400) -- 排序类型
if @doCount <> 0
begin
if @strWhere != ' ' ' '
set @strSQL = 'select count(*) as Total from ' + @tblName + ' where '+@strWhere
else
set @strSQL = 'select count(*) as Total from ' + @tblName + ' '
end
--以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都是@doCount为0的情况:
else
begin
if @OrderType != 0
begin
set @strTmp = ' <(select min '
set @strOrder = ' order by ' + @fldName + ' desc '
end
else
begin
set @strTmp = '> (select max '
set @strOrder = ' order by ' + @fldName + ' asc '
end
if @PageIndex = 1
begin